Skip to content

Commit fbf9ae8

Browse files
committed
chore(cubestore): Upgrade DF: Remove redundant RewriteInListLiterals analysis pass
1 parent 6724cfc commit fbf9ae8

File tree

3 files changed

+86
-99
lines changed

3 files changed

+86
-99
lines changed

rust/cubestore/cubestore-sql-tests/src/tests.rs

Lines changed: 85 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub fn sql_tests(prefix: &str) -> Vec<(&'static str, TestFn)> {
5959
t("in_list", in_list),
6060
t("in_list_with_union", in_list_with_union),
6161
t("numeric_cast", numeric_cast),
62+
t("planning_numeric_cast", planning_numeric_cast),
6263
t("cast_timestamp_to_utf8", cast_timestamp_to_utf8),
6364
t("numbers_to_bool", numbers_to_bool),
6465
t("union", union),
@@ -233,6 +234,10 @@ pub fn sql_tests(prefix: &str) -> Vec<(&'static str, TestFn)> {
233234
"filter_multiple_in_for_decimal",
234235
filter_multiple_in_for_decimal,
235236
),
237+
t(
238+
"planning_filter_multiple_in_for_decimal",
239+
planning_filter_multiple_in_for_decimal,
240+
),
236241
t("panic_worker", panic_worker),
237242
t(
238243
"planning_filter_index_selection",
@@ -346,6 +351,8 @@ lazy_static::lazy_static! {
346351

347352
// New tests
348353
"decimal_math",
354+
"planning_filter_multiple_in_for_decimal",
355+
"planning_numeric_cast",
349356
].into_iter().map(ToOwned::to_owned).collect();
350357
}
351358

@@ -1163,7 +1170,7 @@ async fn in_list_with_union(service: Box<dyn SqlClient>) {
11631170
assert_eq!(result.get_rows()[0], Row::new(vec![TableValue::Int(6)]));
11641171
}
11651172

1166-
async fn numeric_cast(service: Box<dyn SqlClient>) {
1173+
async fn numeric_cast_setup(service: &dyn SqlClient) -> &'static str {
11671174
service.exec_query("CREATE SCHEMA foo").await.unwrap();
11681175

11691176
service
@@ -1175,14 +1182,47 @@ async fn numeric_cast(service: Box<dyn SqlClient>) {
11751182
"INSERT INTO foo.managers (id, department_id) VALUES ('a', 1), ('b', 3), ('c', 3), ('d', 5)"
11761183
).await.unwrap();
11771184

1178-
let result = service
1179-
.exec_query("SELECT count(*) from foo.managers WHERE department_id in ('3', '5')")
1180-
.await
1181-
.unwrap();
1185+
let query = "SELECT count(*) from foo.managers WHERE department_id in ('3', '5')";
1186+
query
1187+
}
1188+
1189+
async fn numeric_cast(service: Box<dyn SqlClient>) {
1190+
let query = numeric_cast_setup(service.as_ref()).await;
1191+
1192+
let result = service.exec_query(query).await.unwrap();
11821193

11831194
assert_eq!(result.get_rows()[0], Row::new(vec![TableValue::Int(3)]));
11841195
}
11851196

1197+
async fn planning_numeric_cast(service: Box<dyn SqlClient>) {
1198+
let query = numeric_cast_setup(service.as_ref()).await;
1199+
1200+
// Check that we're casting '3' to int and not department_id to Utf8, with our Cube-specific type_coercion changes in DF.
1201+
let plans = service.plan_query(query).await.unwrap();
1202+
let expected =
1203+
"Projection, [count(Int64(1))@0:count(*)]\
1204+
\n LinearFinalAggregate\
1205+
\n CoalescePartitions\
1206+
\n ClusterSend, partitions: [[1]]\
1207+
\n CoalescePartitions\
1208+
\n LinearPartialAggregate\
1209+
\n Projection, []\
1210+
\n Filter, predicate: department_id@0 = 3 OR department_id@0 = 5\
1211+
\n Scan, index: default:1:[1], fields: [department_id], predicate: department_id = Int64(3) OR department_id = Int64(5)\
1212+
\n Empty";
1213+
assert_eq!(
1214+
expected,
1215+
pp_phys_plan_ext(
1216+
plans.router.as_ref(),
1217+
&PPOptions {
1218+
traverse_past_clustersend: true,
1219+
show_filters: true,
1220+
..PPOptions::none()
1221+
}
1222+
),
1223+
);
1224+
}
1225+
11861226
async fn cast_timestamp_to_utf8(service: Box<dyn SqlClient>) {
11871227
service.exec_query("CREATE SCHEMA foo").await.unwrap();
11881228

@@ -7552,7 +7592,7 @@ async fn panic_worker(service: Box<dyn SqlClient>) {
75527592
assert_eq!(r, Err(CubeError::panic("worker panic".to_string())));
75537593
}
75547594

7555-
async fn filter_multiple_in_for_decimal(service: Box<dyn SqlClient>) {
7595+
async fn filter_multiple_in_for_decimal_setup(service: &dyn SqlClient) -> &'static str {
75567596
service.exec_query("CREATE SCHEMA s").await.unwrap();
75577597
service
75587598
.exec_query("CREATE TABLE s.t(i decimal)")
@@ -7562,14 +7602,49 @@ async fn filter_multiple_in_for_decimal(service: Box<dyn SqlClient>) {
75627602
.exec_query("INSERT INTO s.t(i) VALUES (1), (2), (3)")
75637603
.await
75647604
.unwrap();
7565-
let r = service
7566-
.exec_query("SELECT count(*) FROM s.t WHERE i in ('2', '3')")
7567-
.await
7568-
.unwrap();
7605+
let query = "SELECT count(*) FROM s.t WHERE i in ('2', '3')";
7606+
query
7607+
}
7608+
7609+
async fn filter_multiple_in_for_decimal(service: Box<dyn SqlClient>) {
7610+
let query = filter_multiple_in_for_decimal_setup(service.as_ref()).await;
7611+
7612+
let r = service.exec_query(query).await.unwrap();
75697613

75707614
assert_eq!(to_rows(&r), rows(&[(2)]));
75717615
}
75727616

7617+
async fn planning_filter_multiple_in_for_decimal(service: Box<dyn SqlClient>) {
7618+
let query = filter_multiple_in_for_decimal_setup(service.as_ref()).await;
7619+
7620+
// Verify we're casting '2' and '3' to decimal type and not casting i to Utf8, with Cube-specific DF comparison coercion changes.
7621+
let plans = service.plan_query(query).await.unwrap();
7622+
let expected =
7623+
"Projection, [count(Int64(1))@0:count(*)]\
7624+
\n LinearFinalAggregate\
7625+
\n CoalescePartitions\
7626+
\n ClusterSend, partitions: [[1]]\
7627+
\n CoalescePartitions\
7628+
\n LinearPartialAggregate\
7629+
\n Projection, []\
7630+
\n Filter, predicate: i@0 = Some(200000),18,5 OR i@0 = Some(300000),18,5\
7631+
\n Scan, index: default:1:[1], fields: *, predicate: i = Decimal128(Some(200000),18,5) OR i = Decimal128(Some(300000),18,5)\
7632+
\n Sort\
7633+
\n Empty";
7634+
7635+
assert_eq!(
7636+
expected,
7637+
pp_phys_plan_ext(
7638+
plans.router.as_ref(),
7639+
&PPOptions {
7640+
traverse_past_clustersend: true,
7641+
show_filters: true,
7642+
..PPOptions::none()
7643+
}
7644+
),
7645+
);
7646+
}
7647+
75737648
async fn planning_aggregate_index(service: Box<dyn SqlClient>) {
75747649
service.exec_query("CREATE SCHEMA s").await.unwrap();
75757650
service

rust/cubestore/cubestore/src/queryplanner/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pub mod serialized_plan;
1717
mod tail_limit;
1818
mod topk;
1919
pub mod trace_data_loaded;
20-
use rewrite_inlist_literals::RewriteInListLiterals;
2120
use serialized_plan::PreSerializedPlan;
2221
pub use topk::MIN_TOPK_STREAM_ROWS;
2322
use udfs::{registerable_aggregate_udfs, registerable_scalar_udfs};
@@ -26,7 +25,6 @@ pub mod info_schema;
2625
pub mod merge_sort;
2726
pub mod metadata_cache;
2827
pub mod providers;
29-
mod rewrite_inlist_literals;
3028
mod rolling;
3129
#[cfg(test)]
3230
mod test_utils;
@@ -283,7 +281,7 @@ impl QueryPlannerImpl {
283281

284282
impl QueryPlannerImpl {
285283
pub fn make_execution_context(mut config: SessionConfig) -> SessionContext {
286-
// The config parameter is from metadata_cache_factor (which we need to rename) but doesn't
284+
// The config parameter is from metadata_cache_factory (which we need to rename) but doesn't
287285
// include all necessary configs.
288286
config
289287
.options_mut()
@@ -297,7 +295,6 @@ impl QueryPlannerImpl {
297295
for udf in registerable_scalar_udfs() {
298296
context.register_udf(udf);
299297
}
300-
context.add_analyzer_rule(Arc::new(RewriteInListLiterals {}));
301298
context.add_optimizer_rule(Arc::new(RollingOptimizerRule {}));
302299

303300
// TODO upgrade DF

rust/cubestore/cubestore/src/queryplanner/rewrite_inlist_literals.rs

Lines changed: 0 additions & 85 deletions
This file was deleted.

0 commit comments

Comments
 (0)