-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cubesql): Support
[NOT] IN
SQL push down
- Loading branch information
1 parent
3e1a075
commit 5da7a43
Showing
8 changed files
with
266 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
rust/cubesql/cubesql/src/compile/rewrite/rules/wrapper/in_list_expr.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
use crate::{ | ||
compile::rewrite::{ | ||
analysis::LogicalPlanAnalysis, inlist_expr, inlist_expr_list, inlist_expr_list_empty_tail, | ||
rewrite, rules::wrapper::WrapperRules, transforming_rewrite, wrapper_pullup_replacer, | ||
wrapper_pushdown_replacer, LogicalPlanLanguage, WrapperPullupReplacerAliasToCube, | ||
}, | ||
var, var_iter, | ||
}; | ||
use egg::{EGraph, Rewrite, Subst}; | ||
|
||
impl WrapperRules { | ||
pub fn in_list_expr_rules( | ||
&self, | ||
rules: &mut Vec<Rewrite<LogicalPlanLanguage, LogicalPlanAnalysis>>, | ||
) { | ||
rules.extend(vec![ | ||
rewrite( | ||
"wrapper-push-down-in-list", | ||
wrapper_pushdown_replacer( | ||
inlist_expr("?expr", "?list", "?negated"), | ||
"?alias_to_cube", | ||
"?ungrouped", | ||
"?cube_members", | ||
), | ||
inlist_expr( | ||
wrapper_pushdown_replacer( | ||
"?expr", | ||
"?alias_to_cube", | ||
"?ungrouped", | ||
"?cube_members", | ||
), | ||
wrapper_pushdown_replacer( | ||
"?list", | ||
"?alias_to_cube", | ||
"?ungrouped", | ||
"?cube_members", | ||
), | ||
"?negated", | ||
), | ||
), | ||
transforming_rewrite( | ||
"wrapper-pull-up-in-list", | ||
inlist_expr( | ||
wrapper_pullup_replacer( | ||
"?expr", | ||
"?alias_to_cube", | ||
"?ungrouped", | ||
"?cube_members", | ||
), | ||
wrapper_pullup_replacer( | ||
"?list", | ||
"?alias_to_cube", | ||
"?ungrouped", | ||
"?cube_members", | ||
), | ||
"?negated", | ||
), | ||
wrapper_pullup_replacer( | ||
inlist_expr("?expr", "?list", "?negated"), | ||
"?alias_to_cube", | ||
"?ungrouped", | ||
"?cube_members", | ||
), | ||
self.transform_in_list_expr("?alias_to_cube"), | ||
), | ||
rewrite( | ||
"wrapper-push-down-in-list-exprs", | ||
wrapper_pushdown_replacer( | ||
inlist_expr_list("?left", "?right"), | ||
"?alias_to_cube", | ||
"?ungrouped", | ||
"?cube_members", | ||
), | ||
inlist_expr_list( | ||
wrapper_pushdown_replacer( | ||
"?left", | ||
"?alias_to_cube", | ||
"?ungrouped", | ||
"?cube_members", | ||
), | ||
wrapper_pushdown_replacer( | ||
"?right", | ||
"?alias_to_cube", | ||
"?ungrouped", | ||
"?cube_members", | ||
), | ||
), | ||
), | ||
rewrite( | ||
"wrapper-pull-up-in-list-exprs", | ||
inlist_expr_list( | ||
wrapper_pullup_replacer( | ||
"?left", | ||
"?alias_to_cube", | ||
"?ungrouped", | ||
"?cube_members", | ||
), | ||
wrapper_pullup_replacer( | ||
"?right", | ||
"?alias_to_cube", | ||
"?ungrouped", | ||
"?cube_members", | ||
), | ||
), | ||
wrapper_pullup_replacer( | ||
inlist_expr_list("?left", "?right"), | ||
"?alias_to_cube", | ||
"?ungrouped", | ||
"?cube_members", | ||
), | ||
), | ||
rewrite( | ||
"wrapper-push-down-in-list-exprs-empty-tail", | ||
wrapper_pushdown_replacer( | ||
inlist_expr_list_empty_tail(), | ||
"?alias_to_cube", | ||
"?ungrouped", | ||
"?cube_members", | ||
), | ||
wrapper_pullup_replacer( | ||
inlist_expr_list_empty_tail(), | ||
"?alias_to_cube", | ||
"?ungrouped", | ||
"?cube_members", | ||
), | ||
), | ||
]); | ||
} | ||
|
||
fn transform_in_list_expr( | ||
&self, | ||
alias_to_cube_var: &'static str, | ||
) -> impl Fn(&mut EGraph<LogicalPlanLanguage, LogicalPlanAnalysis>, &mut Subst) -> bool { | ||
let alias_to_cube_var = var!(alias_to_cube_var); | ||
let meta = self.cube_context.meta.clone(); | ||
move |egraph, subst| { | ||
for alias_to_cube in var_iter!( | ||
egraph[subst[alias_to_cube_var]], | ||
WrapperPullupReplacerAliasToCube | ||
) | ||
.cloned() | ||
{ | ||
if let Some(sql_generator) = meta.sql_generator_by_alias_to_cube(&alias_to_cube) { | ||
if sql_generator | ||
.get_sql_templates() | ||
.templates | ||
.contains_key("expressions/in_list") | ||
{ | ||
return true; | ||
} | ||
} | ||
} | ||
false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters