Skip to content

Commit 3e0d732

Browse files
committed
fix(cubesql): Disable projection_push_down DF optimizer
It can drop projection for mismatched alias in UNION ALL
1 parent 39b8a4a commit 3e0d732

File tree

4 files changed

+53
-10
lines changed

4 files changed

+53
-10
lines changed

rust/cubesql/cubesql/src/compile/query_engine.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -394,15 +394,20 @@ impl QueryEngine for SqlQueryEngine {
394394
state.get_load_request_meta("sql"),
395395
self.config_ref().clone(),
396396
));
397-
let mut ctx = DFSessionContext::with_state(
398-
default_session_builder(
399-
DFSessionConfig::new()
400-
.create_default_catalog_and_schema(false)
401-
.with_information_schema(false)
402-
.with_default_catalog_and_schema("db", "public"),
403-
)
404-
.with_query_planner(query_planner),
405-
);
397+
let mut df_state = default_session_builder(
398+
DFSessionConfig::new()
399+
.create_default_catalog_and_schema(false)
400+
.with_information_schema(false)
401+
.with_default_catalog_and_schema("db", "public"),
402+
)
403+
.with_query_planner(query_planner);
404+
df_state
405+
.optimizer
406+
.rules
407+
// projection_push_down is broken even for non-OLAP queries
408+
// TODO enable it back
409+
.retain(|r| r.name() != "projection_push_down");
410+
let mut ctx = DFSessionContext::with_state(df_state);
406411

407412
if state.protocol == DatabaseProtocol::MySQL {
408413
let system_variable_provider =

rust/cubesql/cubesql/src/compile/snapshots/cubesql__compile__tests__explain-2.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ expression: "execute_query(\"EXPLAIN VERBOSE SELECT 1+1;\".to_string(),\n
1212
| logical_plan after common_sub_expression_eliminate | SAME TEXT AS ABOVE |
1313
| logical_plan after eliminate_limit | SAME TEXT AS ABOVE |
1414
| logical_plan after projection_drop_out | SAME TEXT AS ABOVE |
15-
| logical_plan after projection_push_down | SAME TEXT AS ABOVE |
1615
| logical_plan after filter_push_down | SAME TEXT AS ABOVE |
1716
| logical_plan after limit_push_down | SAME TEXT AS ABOVE |
1817
| logical_plan after SingleDistinctAggregationToGroupBy | SAME TEXT AS ABOVE |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
source: cubesql/src/compile/test/test_df_execution.rs
3+
expression: "execute_query(query.to_string(), DatabaseProtocol::PostgreSQL,).await.unwrap()"
4+
---
5+
+-----+-----+
6+
| foo | bar |
7+
+-----+-----+
8+
| foo | bar |
9+
+-----+-----+

rust/cubesql/cubesql/src/compile/test/test_df_execution.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,33 @@ async fn test_triple_join_with_coercion() {
6161
.await
6262
.unwrap());
6363
}
64+
65+
#[tokio::test]
66+
async fn union_all_alias_mismatch() {
67+
init_testing_logger();
68+
69+
// language=PostgreSQL
70+
let query = r#"
71+
SELECT
72+
foo,
73+
bar
74+
FROM (
75+
SELECT
76+
'foo' as foo,
77+
'bar' as bar
78+
UNION ALL
79+
SELECT
80+
'foo' as foo,
81+
'bar' as qux
82+
) t
83+
GROUP BY
84+
foo, bar
85+
;
86+
"#;
87+
88+
insta::assert_snapshot!(
89+
execute_query(query.to_string(), DatabaseProtocol::PostgreSQL,)
90+
.await
91+
.unwrap()
92+
);
93+
}

0 commit comments

Comments
 (0)