Skip to content

Commit 9d68228

Browse files
committed
started doing transforming_rewrite → "select-distinct-dimensions"
1 parent 245fa3c commit 9d68228

File tree

1 file changed

+53
-2
lines changed
  • rust/cubesql/cubesql/src/compile/rewrite/rules

1 file changed

+53
-2
lines changed

rust/cubesql/cubesql/src/compile/rewrite/rules/members.rs

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::{
44
analysis::{ConstantFolding, LogicalPlanData, MemberNamesToExpr, OriginalExpr},
55
binary_expr, cast_expr, change_user_expr, column_expr, cross_join, cube_scan,
66
cube_scan_filters_empty_tail, cube_scan_members, cube_scan_members_empty_tail,
7-
cube_scan_order_empty_tail, dimension_expr, expr_column_name, fun_expr, join, like_expr,
8-
limit, list_concat_pushdown_replacer, list_concat_pushup_replacer, literal_expr,
7+
cube_scan_order_empty_tail, dimension_expr, distinct, expr_column_name, fun_expr, join,
8+
like_expr, limit, list_concat_pushdown_replacer, list_concat_pushup_replacer, literal_expr,
99
literal_member, measure_expr, member_pushdown_replacer, member_replacer,
1010
merged_members_replacer, original_expr_name, projection, referenced_columns, rewrite,
1111
rewriter::{CubeEGraph, CubeRewrite, RewriteRules},
@@ -262,6 +262,34 @@ impl RewriteRules for MemberRules {
262262
),
263263
self.push_down_limit("?skip", "?fetch", "?new_skip", "?new_fetch"),
264264
),
265+
transforming_rewrite(
266+
"select-distinct-dimensions",
267+
distinct(cube_scan(
268+
"?alias_to_cube",
269+
"?members",
270+
"?filters",
271+
"?orders",
272+
"?limit",
273+
"?offset",
274+
"?split",
275+
"?can_pushdown_join",
276+
"CubeScanWrapped:false",
277+
"?old_ungrouped",
278+
)),
279+
cube_scan(
280+
"?alias_to_cube",
281+
"?members",
282+
"?filters",
283+
"?orders",
284+
"?limit",
285+
"?offset",
286+
"?split",
287+
"?can_pushdown_join",
288+
"CubeScanWrapped:false",
289+
"CubeScanUngrouped:false",
290+
),
291+
self.select_distinct_dimensions("?members", "?limit"),
292+
),
265293
// MOD function to binary expr
266294
transforming_rewrite_with_root(
267295
"mod-fun-to-binary-expr",
@@ -1478,6 +1506,29 @@ impl MemberRules {
14781506
)
14791507
}
14801508

1509+
fn select_distinct_dimensions(
1510+
&self,
1511+
members_var: &'static str,
1512+
limit_var: &'static str,
1513+
) -> impl Fn(&mut CubeEGraph, &mut Subst) -> bool {
1514+
let members_var = var!(members_var);
1515+
let limit_var = var!(limit_var);
1516+
1517+
move |egraph, subst| {
1518+
let cube_limit = var_iter!(egraph[subst[limit_var]], CubeScanLimit)
1519+
.next()
1520+
.unwrap();
1521+
1522+
if cube_limit.is_some() {
1523+
return false;
1524+
}
1525+
1526+
for members in var_list_iter!(egraph[subst[members_var]], CubeScanMembers) {}
1527+
1528+
true
1529+
}
1530+
}
1531+
14811532
fn push_down_non_empty_aggregate(
14821533
&self,
14831534
alias_to_cube_var: &'static str,

0 commit comments

Comments
 (0)