You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Correctness issue with unparsing UNION & UNION ALL #24446
Consider a UNION ALL (b UNION a), that becomes a plan
Union
a
Distinct::All
Union
b
a
This will get incorrectly unparsed as SELECT a UNION SELECT b UNION SELECT a.
All union operations are now distinct, instead of correctly preserving the true per node nature. Root cause: traversing the inner Distinct::All(Union) sets QueryBuilder::distinct_union = true globally. All subsequent Unions are considered distinct during unpausing the query. A single, query-level boolean is insufficient to track ast::SetQuantifier for each UNION operation.
To Reproduce
Add this example case to datafusion/sql/tests/cases/plan_to_sql.rs and rerun.
r#"SELECT j1_string FROM j1 UNION ALL (SELECT j2_string FROM j2 UNION SELECT j1_string FROM j1)"#,
Expected behavior
Actual: the outer ALL is dropped.
SELECT a.x FROM a UNION SELECT b.x FROM b UNION SELECT a.x FROM a
Expected
SELECT a.x FROM a UNION ALL (SELECT b.x FROM b UNION SELECT a.x FROM a)
Activity
shinzoxD commentedon Aug 19, 2026
take
shinzoxD commentedon Aug 19, 2026
Opened #24498