Skip to content

Commit 7a72efa

Browse files
committed
fix(cubesql): Match reverse Tableau year-month extract filter
Signed-off-by: Alex Qyoun-ae <[email protected]>
1 parent 9274201 commit 7a72efa

File tree

2 files changed

+431
-163
lines changed

2 files changed

+431
-163
lines changed

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17883,4 +17883,72 @@ LIMIT {{ limit }}{% endif %}"#.to_string(),
1788317883
}
1788417884
)
1788517885
}
17886+
17887+
#[tokio::test]
17888+
async fn test_tableau_trunc_extract_year_and_month_rev() {
17889+
if !Rewriter::sql_push_down_enabled() {
17890+
return;
17891+
}
17892+
init_testing_logger();
17893+
17894+
let logical_plan = convert_select_to_query_plan(
17895+
r#"
17896+
SELECT SUM("KibanaSampleDataEcommerce"."sumPrice") AS "sum:sumPrice:ok"
17897+
FROM "public"."KibanaSampleDataEcommerce" "KibanaSampleDataEcommerce"
17898+
WHERE (
17899+
"KibanaSampleDataEcommerce"."id" != 0
17900+
AND CAST(TRUNC(EXTRACT(YEAR FROM "KibanaSampleDataEcommerce"."order_date")) AS INTEGER) = 2024
17901+
AND CAST(TRUNC(EXTRACT(MONTH FROM "KibanaSampleDataEcommerce"."order_date")) AS INTEGER) = 2
17902+
AND "KibanaSampleDataEcommerce"."customer_gender" IS NOT NULL
17903+
)
17904+
HAVING COUNT(1) > 0
17905+
"#
17906+
.to_string(),
17907+
DatabaseProtocol::PostgreSQL,
17908+
)
17909+
.await
17910+
.as_logical_plan();
17911+
17912+
assert_eq!(
17913+
logical_plan.find_cube_scan().request,
17914+
V1LoadRequestQuery {
17915+
measures: Some(vec!["KibanaSampleDataEcommerce.sumPrice".to_string(),]),
17916+
dimensions: Some(vec![]),
17917+
segments: Some(vec![]),
17918+
time_dimensions: Some(vec![V1LoadRequestQueryTimeDimension {
17919+
dimension: "KibanaSampleDataEcommerce.order_date".to_string(),
17920+
granularity: None,
17921+
date_range: Some(json!(vec![
17922+
"2024-02-01".to_string(),
17923+
"2024-02-29".to_string(),
17924+
])),
17925+
}]),
17926+
order: Some(vec![]),
17927+
filters: Some(vec![
17928+
V1LoadRequestQueryFilterItem {
17929+
member: Some("KibanaSampleDataEcommerce.id".to_string()),
17930+
operator: Some("notEquals".to_string()),
17931+
values: Some(vec!["0".to_string()]),
17932+
or: None,
17933+
and: None,
17934+
},
17935+
V1LoadRequestQueryFilterItem {
17936+
member: Some("KibanaSampleDataEcommerce.customer_gender".to_string()),
17937+
operator: Some("set".to_string()),
17938+
values: None,
17939+
or: None,
17940+
and: None,
17941+
},
17942+
V1LoadRequestQueryFilterItem {
17943+
member: Some("KibanaSampleDataEcommerce.count".to_string()),
17944+
operator: Some("gt".to_string()),
17945+
values: Some(vec!["0".to_string()]),
17946+
or: None,
17947+
and: None,
17948+
},
17949+
]),
17950+
..Default::default()
17951+
}
17952+
)
17953+
}
1788617954
}

0 commit comments

Comments
 (0)