Skip to content

Commit c5f1648

Browse files
committed
feat(cubesql): Ambiguous column references for SQL push down
1 parent 62b359f commit c5f1648

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

rust/cubesql/cubesql/src/compile/engine/df/wrapper.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,10 @@ impl CubeScanWrapperNode {
745745
truncated_alias.truncate(16);
746746
let mut alias = truncated_alias.clone();
747747
for i in 1..10000 {
748-
if !next_remapping.contains_key(&Column::from_name(&alias)) {
748+
if !next_remapping
749+
.iter()
750+
.any(|(_, v)| v == &Column::from_name(&alias))
751+
{
749752
break;
750753
}
751754
alias = format!("{}_{}", truncated_alias, i);

rust/cubesql/cubesql/src/compile/mod.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19154,6 +19154,58 @@ ORDER BY \"COUNT(count)\" DESC"
1915419154
);
1915519155
}
1915619156

19157+
#[tokio::test]
19158+
async fn test_wrapper_long_alias_names() {
19159+
if !Rewriter::sql_push_down_enabled() {
19160+
return;
19161+
}
19162+
init_logger();
19163+
19164+
let query_plan = convert_select_to_query_plan(
19165+
"SELECT customer_gender AS long_long_long_long_long_long_long_long_a, AVG(avgPrice) AS long_long_long_long_long_long_long_long_b, SUM(COUNT(count)) OVER() AS long_long_long_long_long_long_long_long_c FROM KibanaSampleDataEcommerce a GROUP BY 1 LIMIT 100"
19166+
.to_string(),
19167+
DatabaseProtocol::PostgreSQL,
19168+
)
19169+
.await;
19170+
19171+
let logical_plan = query_plan.as_logical_plan();
19172+
assert!(
19173+
logical_plan
19174+
.find_cube_scan_wrapper()
19175+
.wrapped_sql
19176+
.unwrap()
19177+
.sql
19178+
.contains("long_l_1"),
19179+
"SQL should contain long_l_1: {}",
19180+
logical_plan
19181+
.find_cube_scan_wrapper()
19182+
.wrapped_sql
19183+
.unwrap()
19184+
.sql
19185+
);
19186+
19187+
assert!(
19188+
logical_plan
19189+
.find_cube_scan_wrapper()
19190+
.wrapped_sql
19191+
.unwrap()
19192+
.sql
19193+
.contains("long_l_1"),
19194+
"SQL should contain long_l_2: {}",
19195+
logical_plan
19196+
.find_cube_scan_wrapper()
19197+
.wrapped_sql
19198+
.unwrap()
19199+
.sql
19200+
);
19201+
19202+
let physical_plan = query_plan.as_physical_plan().await.unwrap();
19203+
println!(
19204+
"Physical plan: {}",
19205+
displayable(physical_plan.as_ref()).indent()
19206+
);
19207+
}
19208+
1915719209
#[tokio::test]
1915819210
async fn test_thoughtspot_pg_date_trunc_year() {
1915919211
init_logger();

0 commit comments

Comments
 (0)