-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Alias map is not propagated into UNION / EXCEPT / INTERSECT branches
transform_setexpr
only gathers aliases when the set expression is a plain SELECT
. For SetExpr::SetOperation { left, right, .. }
(UNION, EXCEPT, etc.) the left/right branches are skipped, so correlated columns in those arms won’t be resolved with alias awareness.
Add handling for the other SetExpr
variants, delegating to the existing logic for each branch:
match sexpr {
SetExpr::Select(s) => { ... }
+ SetExpr::SetOperation { left, right, .. } => {
+ transform_setexpr(left, ctx, names).await?;
+ transform_setexpr(right, ctx, names).await?;
+ }
_ => {}
}
Without this, queries containing sub-queries under UNIONs will silently regress to the old (alias-blind) behaviour.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
match sexpr {
SetExpr::Select(s) => {
let aliases = collect_aliases(s);
for item in &mut s.projection {
match item {
SelectItem::UnnamedExpr(e) => {
transform_expr(e, ctx, names, &aliases).await?;
}
SelectItem::ExprWithAlias { expr, .. } => {
transform_expr(expr, ctx, names, &aliases).await?;
}
_ => {}
}
}
if let Some(e) = &mut s.selection {
transform_expr(e, ctx, names, &aliases).await?;
}
}
SetExpr::SetOperation { left, right, .. } => {
transform_setexpr(left, ctx, names).await?;
transform_setexpr(right, ctx, names).await?;
}
_ => {}
}
🤖 Prompt for AI Agents
In src/lib.rs around lines 114 to 129, the current code only collects aliases
and transforms expressions for plain SELECT set expressions, ignoring SetExpr
variants like UNION, EXCEPT, and INTERSECT. To fix this, extend the match
handling in transform_setexpr to recursively process the left and right branches
of SetOperation variants by calling transform_setexpr on them, ensuring alias
maps are propagated and correlated columns in these branches are resolved
correctly.
Originally posted by @coderabbitai[bot] in #16 (comment)