Skip to content

feat(parser): parse arithmetic operators in value expressions - #169

Open
JayPokale wants to merge 1 commit into
lance-format:mainfrom
JayPokale:feat/parse-arithmetic
Open

JayPokale wants to merge 1 commit into
lance-format:mainfrom
JayPokale:feat/parse-arithmetic

Conversation

@JayPokale

@JayPokale JayPokale commented Oct 25, 2026 •

Copy link
Copy Markdown

The AST, the semantic analyzer and the DataFusion planner already handle ValueExpression::Arithmetic (#13, #68), but the parser never builds it, so any query with an arithmetic operator fails to parse:

MATCH (p:Person) RETURN p.age + 1 AS next_age
Cypher parse error at position 30: Unexpected input after query: + 1 AS next_age

This adds arithmetic to value_expression:

  • + and - bind looser than *, / and %; all are left-associative (10 - 4 - 3 is (10 - 4) - 3).
  • Parenthesized sub-expressions: (p.age + 1) * 2.
  • Works anywhere a value expression is accepted, so WHERE p.age / 5 - 1 >= 5 works too.
  • COUNT(*) is unaffected, because the * argument is matched before the argument list is parsed.

Tests:

  • Parser unit tests for precedence, associativity, parentheses, n.age-1 without spaces, arithmetic inside a WHERE comparison, and count(*) * 2.
  • tests/test_arithmetic_expressions.rs runs RETURN and WHERE arithmetic end to end on the DataFusion executor and checks the values.

Commands run in crates/lance-graph: cargo test (all unit, integration and doc tests pass), cargo fmt --all -- --check, cargo clippy --all-targets -- -D warnings.

I used an AI assistant (Claude) while working on this; I reviewed and tested the change.

The AST, semantic analysis and the DataFusion planner already support
ValueExpression::Arithmetic, but the parser never produced it, so queries
such as RETURN n.age + 1 or WHERE n.age * 2 > 50 failed to parse.

Parse +, -, *, / and % with the usual precedence and left associativity,
and allow parenthesized sub-expressions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant