Skip to content

fix: denormalized node alias rewriting in WITH CTE body#224

Merged
genezhang merged 2 commits intomainfrom
fix/denormalized-with-cte-alias
Mar 13, 2026
Merged

fix: denormalized node alias rewriting in WITH CTE body#224
genezhang merged 2 commits intomainfrom
fix/denormalized-with-cte-alias

Conversation

@genezhang
Copy link
Copy Markdown
Owner

Summary

  • When denormalized schemas embed node properties in the edge table, WITH clause CTE rendering generated invalid SQL like SELECT a.OriginCityName when the FROM clause only has flights AS r (no a alias exists)
  • Added rewrite_denormalized_aliases_in_expr() in plan_builder_utils.rs that detects denormalized nodes via get_properties_with_table_alias() and rewrites a.Xr.X in CTE SELECT and GROUP BY expressions
  • Removed xfail markers from 3 now-passing denormalized WITH aggregation tests; updated xfail reasons on 3 remaining tests (different root cause: unmapped property names)

Test plan

  • All 1,588 Rust unit tests pass
  • Denormalized edge tests: 14 passed, 4 xfailed (unchanged)
  • Pattern schema matrix: 0 xpassed (clean), 3 denormalized WITH agg tests promoted from xfail to pass
  • Pattern matrix: 0 xpassed (clean), 1 denormalized WITH agg test promoted from xfail to pass
  • No regressions in schema variations comprehensive tests (77 passed)

🤖 Generated with Claude Code

genezhang and others added 2 commits March 12, 2026 22:30
When a denormalized schema embeds node properties in the edge table,
the FROM clause aliases the table with the edge alias (e.g., `flights AS r`).
Property access on denormalized nodes (e.g., `a.city`) must be rewritten
to use the edge alias (`r.OriginCityName`). The property name mapping was
already handled by `rewrite_expression_with_property_mapping`, but the
table alias was not being rewritten in the WITH CTE rendering path.

Add `rewrite_denormalized_aliases_in_expr()` that uses
`get_properties_with_table_alias()` to detect denormalized nodes and
rewrite their aliases in SELECT items and GROUP BY expressions during
CTE body construction.

Fixes 3 denormalized WITH aggregation integration tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@genezhang genezhang merged commit 0ca5824 into main Mar 13, 2026
4 checks passed
@genezhang genezhang deleted the fix/denormalized-with-cte-alias branch March 13, 2026 05:56
genezhang added a commit that referenced this pull request Mar 13, 2026
Enhance resolve_denormalized_property_in_expr() to handle both table alias
rewriting AND property name mapping using get_properties_with_table_alias().

Key improvements:
- Property name resolution now correctly distinguishes from_node vs to_node
  (e.g., a.city → r.OriginCityName, b.city → r.DestCityName)
- Cross-side correction: when schema mapping maps to wrong side's column
  (e.g., b.city → OriginCityName), reverse-lookups through node schema's
  from_properties/to_properties to find the correct Cypher property name,
  then resolves through the correct side's denormalized mapping
- Also handles CASE expressions and covers coupled schema aliases

Fixes 6 more integration tests across denormalized and coupled schemas.
Total: 9 tests promoted from xfail to passing (3 from PR #224 + 6 here).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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