lance-format / lance-format/lance-graph

Parser rejects boolean comparison after `COUNT(DISTINCT ...)` during projection

Open
#123 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
179
Forks
33
PR merge metrics
No merged PRs in 30d

Description

The Cypher parser fails when a boolean comparison is applied to an aggregate in RETURN.

Version

Tested on lance-graph 0.5.0 (Python).

Repro

import pyarrow as pa
from lance_graph import CypherQuery, GraphConfig


def build_graph() -> tuple[GraphConfig, dict[str, pa.Table]]:
    cfg = (
        GraphConfig.builder()
        .with_node_label("Person", "id")
        .with_node_label("Post", "id")
        .with_relationship("likePost", "src", "dst")
        .build()
    )

    datasets: dict[str, pa.Table] = {
        "Person": pa.table(
            {"id": [1], "firstname": ["Bill"], "lastname": ["Moore"]}
        ),
        "Post": pa.table({"id": [1]}),
        "likePost": pa.table({"src": [1], "dst": [1]}),
    }
    return cfg, datasets


def execute(query: str, cfg: GraphConfig, datasets: dict[str, pa.Table]):
    cypher = CypherQuery(query)
    return cypher.with_config(cfg).execute(datasets)


def main() -> None:
    cfg, datasets = build_graph()
    q1 = """
        MATCH (p:Post)<-[:likePost]-(p2:Person)
        WHERE p2.firstname = "Bill" AND p2.lastname = "Moore"
          AND p.id = 1
        RETURN COUNT(DISTINCT p.id) AS liked
    """
    q2 = """
        MATCH (p:Post)<-[:likePost]-(p2:Person)
        WHERE p2.firstname = "Bill" AND p2.lastname = "Moore"
          AND p.id = 2
        RETURN COUNT(DISTINCT p.id) > 0 AS liked
    """

    print("Running query without comparison:")
    print(execute(q1, cfg, datasets))

    print("\nRunning query with comparison (expected to fail):")
    try:
        print(execute(q2, cfg, datasets))
    except Exception as exc:  # noqa: BLE001 - minimal repro script
        print(f"ERROR: {exc}")


if __name__ == "__main__":
    main()

This gives:

❯ uv run repro_count_distinct_bool.py
Running query without comparison:
pyarrow.Table
liked: int64 not null
----
liked: [[1]]

Running query with comparison (expected to fail):
ERROR: Cypher parse error at position 170: Unexpected input after query: > 0 AS liked

Expected

The second query should return a boolean TRUE or FALSE based on the condition it's checking for.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided repro through CypherQuery, comparing the working COUNT(DISTINCT p.id) projection with the failing boolean comparison. Trace the parser entry point used by CypherQuery for RETURN expressions; done means the second query parses and returns a boolean TRUE or FALSE.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.