query_graph Cypher: coalesce() in WHERE rejected (unexpected operator)
Summary
The Cypher subset used by query_graph rejects coalesce() in WHERE clauses. This blocks common null-safe numeric filters (e.g. complexity / hot-path audits over optional graph properties).
Environment
- Binary:
codebase-memory-mcp 0.8.1(linux-amd64) - Project:
home-sean-campbell-github-willow-2.0(public: willow-2.0)
Reproduction
MATCH (f:Function) WHERE coalesce(f.transitive_loop_depth, 0) >= 2 RETURN f.qualified_name LIMIT 10
Result: parser error — unexpected operator at pos 33 (at coalesce).
Direct property comparisons work; only the coalesce() wrapper fails.
Expected
coalesce(expr, default) in WHERE (or documented as unsupported with a clear error listing supported functions).
Impact
Audit queries that need null-safe thresholds must issue one query per property or avoid arithmetic — easy to miss when porting Cypher from other engines.
Related
Cypher hardening / subset documentation. Distinct from #237 (DISTINCT ordering) but same tool surface (query_graph).
Confirmations
- [x] Searched issues for
coalesce— no duplicate found. - [x] Public OSS index (willow-2.0).
Thanks for the concise Cypher repro. Triage: query-language bug under #594. If coalesce is meant to be part of the supported subset, this needs parser/evaluator coverage in WHERE; if not, the error should be explicit about unsupported functions rather than surfacing as an unexpected operator.
Hi, I would like to work on this. I dug into the parser and the root cause is that parse_condition_expr() in src/cypher/cypher.c only accepts var, var.prop or var:Label on the left side of a WHERE condition, so it trips on the ( after coalesce and reports "unexpected operator". Since coalesce() is already supported in RETURN via parse_multiarg_func_item() and eval_multiarg_func(), my plan is to reuse those in the WHERE path, and make unrecognized functions in WHERE fail with a clear "unsupported function" error listing the supported ones, as suggested in triage. Will add regression tests in tests/test_cypher.c covering the repro query. PR coming shortly.
Fixed on main in b0aead25 (PR #991): WHERE-clause now supports the same multi-arg scalar functions as RETURN — coalesce(), substring(), replace(), left(), right() — by routing the condition LHS through the shared multi-arg evaluator, and unknown functions now raise a clear error instead of silently mis-parsing. Thanks @harshitaajoshi!