fix: qualify bare Column expressions in denormalized UNION branches#228
fix: qualify bare Column expressions in denormalized UNION branches#228
Conversation
Denormalized ViewScans produce bare Column("OriginCityName") expressions
without table qualifiers. The SQL renderer's Column.to_sql() fallback
guesses "t" as the alias, producing invalid SQL like `t.OriginCityName`
when the FROM alias is actually "r".
Two-level fix:
1. plan_builder.rs: Qualify Column→PropertyAccessExp in GraphNode's UNION
branches using the node alias (catches denormalized standalone scans)
2. to_sql_query.rs: qualify_bare_columns_from_alias() qualifies remaining
bare Columns using FROM alias before SQL rendering (catches UNION
branches created through other paths)
Promotes 3 denormalized simple_agg tests from xfail to passing.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Code ReviewConcern: Duplicate qualification logicThe same bare-Column → PropertyAccessExp transformation is applied in two places:
If fix #1 works correctly, fix #2 will find no bare
Suggestion: The The fix itself is correct ✅The core logic is sound — bare Test changes ✅The 3 Minor nit
|
Per review feedback, keep only the plan_builder.rs fix (qualifies bare Column expressions at plan construction time) and remove the redundant catch-all in to_sql_query.rs. The plan_builder.rs location is more principled — it fixes the data model rather than patching at render time. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
Column("OriginCityName")expressions without table qualifiers, causing the SQL renderer to guesstas the alias instead of the correct FROM alias (e.g.,r)Column→PropertyAccessExpin plan_builder.rs (GraphNode UNION branches) and to_sql_query.rs (catch-all before SQL rendering)simple_aggtests from xfail to passing (132 passed, 32 skipped, 40 xfailed)Test plan
cargo fmt --allandcargo clippy --all-targetsclean🤖 Generated with Claude Code