Skip to content

Commit 8398538

Browse files
authored
feat(cubesql): Match Tableau year-month extract filter pair as inDateRange (#9991)
1 parent 314da63 commit 8398538

File tree

2 files changed

+289
-51
lines changed

2 files changed

+289
-51
lines changed

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17815,4 +17815,72 @@ LIMIT {{ limit }}{% endif %}"#.to_string(),
1781517815
}
1781617816
)
1781717817
}
17818+
17819+
#[tokio::test]
17820+
async fn test_tableau_trunc_extract_year_and_month() {
17821+
if !Rewriter::sql_push_down_enabled() {
17822+
return;
17823+
}
17824+
init_testing_logger();
17825+
17826+
let logical_plan = convert_select_to_query_plan(
17827+
r#"
17828+
SELECT SUM("KibanaSampleDataEcommerce"."sumPrice") AS "sum:sumPrice:ok"
17829+
FROM "public"."KibanaSampleDataEcommerce" "KibanaSampleDataEcommerce"
17830+
WHERE (
17831+
"KibanaSampleDataEcommerce"."id" != 0
17832+
AND CAST(TRUNC(EXTRACT(MONTH FROM "KibanaSampleDataEcommerce"."order_date")) AS INTEGER) = 2
17833+
AND CAST(TRUNC(EXTRACT(YEAR FROM "KibanaSampleDataEcommerce"."order_date")) AS INTEGER) = 2024
17834+
AND "KibanaSampleDataEcommerce"."customer_gender" IS NOT NULL
17835+
)
17836+
HAVING COUNT(1) > 0
17837+
"#
17838+
.to_string(),
17839+
DatabaseProtocol::PostgreSQL,
17840+
)
17841+
.await
17842+
.as_logical_plan();
17843+
17844+
assert_eq!(
17845+
logical_plan.find_cube_scan().request,
17846+
V1LoadRequestQuery {
17847+
measures: Some(vec!["KibanaSampleDataEcommerce.sumPrice".to_string(),]),
17848+
dimensions: Some(vec![]),
17849+
segments: Some(vec![]),
17850+
time_dimensions: Some(vec![V1LoadRequestQueryTimeDimension {
17851+
dimension: "KibanaSampleDataEcommerce.order_date".to_string(),
17852+
granularity: None,
17853+
date_range: Some(json!(vec![
17854+
"2024-02-01".to_string(),
17855+
"2024-02-29".to_string(),
17856+
])),
17857+
}]),
17858+
order: Some(vec![]),
17859+
filters: Some(vec![
17860+
V1LoadRequestQueryFilterItem {
17861+
member: Some("KibanaSampleDataEcommerce.id".to_string()),
17862+
operator: Some("notEquals".to_string()),
17863+
values: Some(vec!["0".to_string()]),
17864+
or: None,
17865+
and: None,
17866+
},
17867+
V1LoadRequestQueryFilterItem {
17868+
member: Some("KibanaSampleDataEcommerce.customer_gender".to_string()),
17869+
operator: Some("set".to_string()),
17870+
values: None,
17871+
or: None,
17872+
and: None,
17873+
},
17874+
V1LoadRequestQueryFilterItem {
17875+
member: Some("KibanaSampleDataEcommerce.count".to_string()),
17876+
operator: Some("gt".to_string()),
17877+
values: Some(vec!["0".to_string()]),
17878+
or: None,
17879+
and: None,
17880+
},
17881+
]),
17882+
..Default::default()
17883+
}
17884+
)
17885+
}
1781817886
}

0 commit comments

Comments
 (0)