Skip to content

Commit

Permalink
feat(cubesql): Metabase - BETWEEN filters support (#4852)
Browse files Browse the repository at this point in the history
  • Loading branch information
gandronchik committed Jul 12, 2022
1 parent eecf776 commit b191120
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
36 changes: 36 additions & 0 deletions rust/cubesql/cubesql/src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9930,5 +9930,41 @@ ORDER BY \"COUNT(count)\" DESC"
}
)
}

let logical_plan = convert_select_to_query_plan(
"SELECT \"source\".\"count\" AS \"count\"
FROM (
SELECT \"public\".\"KibanaSampleDataEcommerce\".\"count\" AS \"count\" FROM \"public\".\"KibanaSampleDataEcommerce\"
WHERE \"public\".\"KibanaSampleDataEcommerce\".\"order_date\"
BETWEEN timestamp with time zone '2022-06-13 12:30:00.000Z'
AND timestamp with time zone '2022-06-29 12:30:00.000Z'
)
\"source\""
.to_string(),
DatabaseProtocol::PostgreSQL,
)
.await
.as_logical_plan();

assert_eq!(
logical_plan.find_cube_scan().request,
V1LoadRequestQuery {
measures: Some(vec!["KibanaSampleDataEcommerce.count".to_string()]),
dimensions: Some(vec![]),
segments: Some(vec![]),
time_dimensions: Some(vec![V1LoadRequestQueryTimeDimension {
dimension: "KibanaSampleDataEcommerce.order_date".to_string(),
granularity: None,
date_range: Some(json!(vec![
"2022-06-13 12:30:00.000Z".to_string(),
"2022-06-29 12:30:00.000Z".to_string()
]))
}]),
order: None,
limit: None,
offset: None,
filters: None
}
)
}
}
17 changes: 16 additions & 1 deletion rust/cubesql/cubesql/src/compile/rewrite/rules/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,21 @@ impl RewriteRules for FilterRules {
filter_cast_unwrap_replacer("?else"),
),
),
rewrite(
"filter-cast-unwrap-between-push-down",
filter_cast_unwrap_replacer(between_expr(
column_expr("?column"),
"?negated",
"?low",
"?high",
)),
between_expr(
column_expr("?column"),
"?negated",
filter_cast_unwrap_replacer("?low"),
filter_cast_unwrap_replacer("?high"),
),
),
filter_unwrap_cast_push_down("CaseExprExpr"),
filter_unwrap_cast_push_down_tail("CaseExprExpr"),
filter_unwrap_cast_push_down("CaseExprWhenThenExpr"),
Expand Down Expand Up @@ -1391,7 +1406,7 @@ impl FilterRules {
members_var,
table_name_var,
) {
if let Some(_) = cube.lookup_dimension(&member_name) {
if let Some(_) = cube.lookup_dimension_by_member_name(&member_name) {
for negated in var_iter!(egraph[subst[negated_var]], BetweenExprNegated) {
let negated = *negated;
if let Some(ConstantFolding::Scalar(low)) =
Expand Down

0 comments on commit b191120

Please sign in to comment.