Skip to content

Commit f179794

Browse files
MazterQyouigorlukanin
authored andcommitted
fix(cubesql): Match reverse Tableau year-month extract filter (#10009)
1 parent 6f0b088 commit f179794

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
@@ -17721,4 +17721,72 @@ LIMIT {{ limit }}{% endif %}"#.to_string(),
1772117721
}
1772217722
)
1772317723
}
17724+
17725+
#[tokio::test]
17726+
async fn test_tableau_trunc_extract_year_and_month_rev() {
17727+
if !Rewriter::sql_push_down_enabled() {
17728+
return;
17729+
}
17730+
init_testing_logger();
17731+
17732+
let logical_plan = convert_select_to_query_plan(
17733+
r#"
17734+
SELECT SUM("KibanaSampleDataEcommerce"."sumPrice") AS "sum:sumPrice:ok"
17735+
FROM "public"."KibanaSampleDataEcommerce" "KibanaSampleDataEcommerce"
17736+
WHERE (
17737+
"KibanaSampleDataEcommerce"."id" != 0
17738+
AND CAST(TRUNC(EXTRACT(YEAR FROM "KibanaSampleDataEcommerce"."order_date")) AS INTEGER) = 2024
17739+
AND CAST(TRUNC(EXTRACT(MONTH FROM "KibanaSampleDataEcommerce"."order_date")) AS INTEGER) = 2
17740+
AND "KibanaSampleDataEcommerce"."customer_gender" IS NOT NULL
17741+
)
17742+
HAVING COUNT(1) > 0
17743+
"#
17744+
.to_string(),
17745+
DatabaseProtocol::PostgreSQL,
17746+
)
17747+
.await
17748+
.as_logical_plan();
17749+
17750+
assert_eq!(
17751+
logical_plan.find_cube_scan().request,
17752+
V1LoadRequestQuery {
17753+
measures: Some(vec!["KibanaSampleDataEcommerce.sumPrice".to_string(),]),
17754+
dimensions: Some(vec![]),
17755+
segments: Some(vec![]),
17756+
time_dimensions: Some(vec![V1LoadRequestQueryTimeDimension {
17757+
dimension: "KibanaSampleDataEcommerce.order_date".to_string(),
17758+
granularity: None,
17759+
date_range: Some(json!(vec![
17760+
"2024-02-01".to_string(),
17761+
"2024-02-29".to_string(),
17762+
])),
17763+
}]),
17764+
order: Some(vec![]),
17765+
filters: Some(vec![
17766+
V1LoadRequestQueryFilterItem {
17767+
member: Some("KibanaSampleDataEcommerce.id".to_string()),
17768+
operator: Some("notEquals".to_string()),
17769+
values: Some(vec!["0".to_string()]),
17770+
or: None,
17771+
and: None,
17772+
},
17773+
V1LoadRequestQueryFilterItem {
17774+
member: Some("KibanaSampleDataEcommerce.customer_gender".to_string()),
17775+
operator: Some("set".to_string()),
17776+
values: None,
17777+
or: None,
17778+
and: None,
17779+
},
17780+
V1LoadRequestQueryFilterItem {
17781+
member: Some("KibanaSampleDataEcommerce.count".to_string()),
17782+
operator: Some("gt".to_string()),
17783+
values: Some(vec!["0".to_string()]),
17784+
or: None,
17785+
and: None,
17786+
},
17787+
]),
17788+
..Default::default()
17789+
}
17790+
)
17791+
}
1772417792
}

0 commit comments

Comments
 (0)