Skip to content

Commit 16e2ee0

Browse files
committed
feat(cubesql): Support split and SUM(1)
1 parent 76038a2 commit 16e2ee0

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3305,6 +3305,32 @@ mod tests {
33053305
);
33063306
}
33073307

3308+
#[tokio::test]
3309+
async fn sum_to_count_push_down() {
3310+
init_logger();
3311+
3312+
let query_plan = convert_select_to_query_plan(
3313+
"SELECT SUM(1) AS \"count\" FROM \"public\".\"KibanaSampleDataEcommerce\" \"KibanaSampleDataEcommerce\"".to_string(),
3314+
DatabaseProtocol::PostgreSQL,
3315+
).await;
3316+
3317+
let logical_plan = query_plan.as_logical_plan();
3318+
assert_eq!(
3319+
logical_plan.find_cube_scan().request,
3320+
V1LoadRequestQuery {
3321+
measures: Some(vec!["KibanaSampleDataEcommerce.count".to_string()]),
3322+
segments: Some(vec![]),
3323+
dimensions: Some(vec![]),
3324+
time_dimensions: None,
3325+
order: None,
3326+
limit: None,
3327+
offset: None,
3328+
filters: None,
3329+
ungrouped: None,
3330+
}
3331+
);
3332+
}
3333+
33083334
#[tokio::test]
33093335
async fn tableau_having_count_on_cube_without_count() {
33103336
if !Rewriter::sql_push_down_enabled() {

rust/cubesql/cubesql/src/compile/rewrite/rules/split/aggregate_function.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,28 @@ impl SplitRules {
7676
true,
7777
rules,
7878
);
79+
self.single_arg_split_point_rules(
80+
"aggregate-function-sum-count-constant",
81+
|| agg_fun_expr("?fun_name", vec![literal_int(1)], "?distinct"),
82+
|| {
83+
agg_fun_expr(
84+
"Count",
85+
vec![literal_int(1)],
86+
"AggregateFunctionExprDistinct:false",
87+
)
88+
},
89+
|alias_column| agg_fun_expr("?output_fun_name", vec![alias_column], "?distinct"),
90+
self.transform_aggregate_function(
91+
Some("?fun_name"),
92+
None,
93+
Some("?distinct"),
94+
"?output_fun_name",
95+
"?alias_to_cube",
96+
true,
97+
),
98+
true,
99+
rules,
100+
);
79101
self.single_arg_split_point_rules(
80102
"aggregate-function-invariant-constant",
81103
|| agg_fun_expr("?fun_name", vec!["?constant"], "?distinct"),

rust/cubesql/cubesql/src/compile/rewrite/rules/split/top_level.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl SplitRules {
109109
"?orders",
110110
"?limit",
111111
"?offset",
112-
"CubeScanSplit:false",
112+
"CubeScanSplit:true",
113113
"?can_pushdown_join",
114114
"CubeScanWrapped:false",
115115
"?ungrouped",
@@ -214,7 +214,7 @@ impl SplitRules {
214214
"?orders",
215215
"?limit",
216216
"?offset",
217-
"CubeScanSplit:false",
217+
"CubeScanSplit:true",
218218
"?can_pushdown_join",
219219
"CubeScanWrapped:false",
220220
"?ungrouped",

0 commit comments

Comments
 (0)