Skip to content

WITH clause fails to parse, despite being mentioned in DeepWiki docs #102

Closed

Description

@prrao87

Summary

Running a query that uses a WITH clause causes a parse error, even though the docs say it’s supported.

Example

import pyarrow as pa
from lance_graph import GraphConfig, CypherQuery

people = pa.table({"id": [1, 2]})
follows = pa.table({"src": [1], "dst": [2]})
cfg = (
    GraphConfig.builder()
    .with_node_label("Person", "id")
    .with_relationship("FOLLOWS", "src", "dst")
    .build()
)
datasets = {"Person": people, "FOLLOWS": follows}

query = """
MATCH (a:Person)-[:FOLLOWS]->(b:Person)
WITH b, count(a.id) AS n
RETURN b.id, n
"""
CypherQuery(query).with_config(cfg).execute(datasets)

Expected

Query executes, returning counts per b.

Actual

  • ValueError: Cypher parse error ... input: WITH b, count(...)

Proposal

Rewriting without WITH works, but loses some expressiveness. But WITH does help a lot of Cypher beginners write queries as they're learning, so it's a useful add.

Environment

The following environment was used to test this:

lance-graph 0.4.0
Python 3.13
macOS Tahoe 26.2

Activity

  1. prrao87 commented on Jan 27, 2026

    @prrao87
    ContributorAuthor

    Related to #86, hopefully can test this on the real datasets once a new release of lance-graph is made.

  2. aheev commented on Jan 27, 2026

    @aheev
    Contributor

    I'm getting the following error when running in local

    >>> CypherQuery(query).with_config(cfg).explain(datasets)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: Query planning error: Failed to build aggregate: Schema error: No field named b. Valid fields are a__id, follows_1__src, follows_1__dst, b__id, a__id, follows_1__src, follows_1__dst, b__id.
    
  3. aheev commented on Jan 27, 2026

    @aheev
    Contributor

    @prrao87 Got it. You can't alias whole nodes or relationships. For ex below query works

    MATCH (a:Person)-[:FOLLOWS]->(b:Person)
    WITH a.id as c
    RETURN c
  4. aheev commented on Jan 27, 2026

    @aheev
    Contributor

    raised new issue: #109

  5. prrao87 commented on Jan 27, 2026

    @prrao87
    ContributorAuthor

    Ah yes, but this is the pattern I need to use. And combining WITH with DISTINCT doesn't seem to work.

    MATCH (p:Person)<-[:commentHasCreator]-(c:Comment)<-[:likeComment]-(p2:Person)
    WHERE p.firstName = "Rafael" AND p.lastName = "Alonso"
    WITH DISTINCT p2.ID AS id
    RETURN count(id) AS num_persons;

    Gives:

    Traceback (most recent call last):
      File "/Users/prrao/code/graph-benchmark-ldbc-snb/lance_graph/query.py", line 490, in <module>
        main(selected_queries)
        ~~~~^^^^^^^^^^^^^^^^^^
      File "/Users/prrao/code/graph-benchmark-ldbc-snb/lance_graph/query.py", line 483, in main
        func(cfg, datasets)
        ~~~~^^^^^^^^^^^^^^^
      File "/Users/prrao/code/graph-benchmark-ldbc-snb/lance_graph/query.py", line 252, in run_query13
        return _execute(cfg, datasets, 13, query)
      File "/Users/prrao/code/graph-benchmark-ldbc-snb/lance_graph/query.py", line 119, in _execute
        result = execute_query(query, cfg, datasets)
      File "/Users/prrao/code/graph-benchmark-ldbc-snb/lance_graph/query.py", line 107, in execute_query
        cypher = CypherQuery(query)
    ValueError: Cypher parse error at position 0: Failed to parse Cypher query: Parsing Error: Error { input: "WITH DISTINCT p2.ID AS id\nRETURN count(id) AS num_persons;\n    ", code: Tag }
    
  6. aheev commented on Jan 28, 2026

    @aheev
    Contributor

    Ah yes, but this is the pattern I need to use. And combining WITH with DISTINCT doesn't seem to work.

    MATCH (p:Person)<-[:commentHasCreator]-(c:Comment)<-[:likeComment]-(p2:Person)
    WHERE p.firstName = "Rafael" AND p.lastName = "Alonso"
    WITH DISTINCT p2.ID AS id
    RETURN count(id) AS num_persons;
    Gives:

    Traceback (most recent call last):
      File "/Users/prrao/code/graph-benchmark-ldbc-snb/lance_graph/query.py", line 490, in <module>
        main(selected_queries)
        ~~~~^^^^^^^^^^^^^^^^^^
      File "/Users/prrao/code/graph-benchmark-ldbc-snb/lance_graph/query.py", line 483, in main
        func(cfg, datasets)
        ~~~~^^^^^^^^^^^^^^^
      File "/Users/prrao/code/graph-benchmark-ldbc-snb/lance_graph/query.py", line 252, in run_query13
        return _execute(cfg, datasets, 13, query)
      File "/Users/prrao/code/graph-benchmark-ldbc-snb/lance_graph/query.py", line 119, in _execute
        result = execute_query(query, cfg, datasets)
      File "/Users/prrao/code/graph-benchmark-ldbc-snb/lance_graph/query.py", line 107, in execute_query
        cypher = CypherQuery(query)
    ValueError: Cypher parse error at position 0: Failed to parse Cypher query: Parsing Error: Error { input: "WITH DISTINCT p2.ID AS id\nRETURN count(id) AS num_persons;\n    ", code: Tag }
    

    It's already listed here

  7. prrao87 commented on Feb 2, 2026

    @prrao87
    ContributorAuthor

    Fixed in 0.5.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions