File tree Expand file tree Collapse file tree 2 files changed +72
-0
lines changed
rust/cubesql/cubesql/src/compile Expand file tree Collapse file tree 2 files changed +72
-0
lines changed Original file line number Diff line number Diff line change @@ -18124,4 +18124,50 @@ LIMIT {{ limit }}{% endif %}"#.to_string(),
1812418124 }
1812518125 )
1812618126 }
18127+
18128+ #[tokio::test]
18129+ async fn test_cast_as_date_filter() {
18130+ if !Rewriter::sql_push_down_enabled() {
18131+ return;
18132+ }
18133+ init_testing_logger();
18134+
18135+ let logical_plan = convert_select_to_query_plan(
18136+ r#"
18137+ SELECT
18138+ SUM(sumPrice) AS s,
18139+ CAST(customer_gender AS TEXT) AS g
18140+ FROM KibanaSampleDataEcommerce
18141+ WHERE
18142+ CAST(order_date AS DATE) >= (DATE '2025-07-02')
18143+ AND CAST(order_date AS DATE) <= (DATE '2025-09-30')
18144+ GROUP BY 2
18145+ "#
18146+ .to_string(),
18147+ DatabaseProtocol::PostgreSQL,
18148+ )
18149+ .await
18150+ .as_logical_plan();
18151+
18152+ assert_eq!(
18153+ logical_plan.find_cube_scan().request,
18154+ V1LoadRequestQuery {
18155+ measures: Some(vec!["KibanaSampleDataEcommerce.sumPrice".to_string(),]),
18156+ dimensions: Some(vec![
18157+ "KibanaSampleDataEcommerce.customer_gender".to_string(),
18158+ ]),
18159+ segments: Some(vec![]),
18160+ time_dimensions: Some(vec![V1LoadRequestQueryTimeDimension {
18161+ dimension: "KibanaSampleDataEcommerce.order_date".to_string(),
18162+ granularity: None,
18163+ date_range: Some(json!(vec![
18164+ "2025-07-02T00:00:00.000Z".to_string(),
18165+ "2025-09-30T23:59:59.999Z".to_string(),
18166+ ])),
18167+ }]),
18168+ order: Some(vec![]),
18169+ ..Default::default()
18170+ }
18171+ )
18172+ }
1812718173}
Original file line number Diff line number Diff line change @@ -2198,6 +2198,32 @@ impl RewriteRules for FilterRules {
21982198 not_expr( binary_expr( "?left" , "LIKE" , "?right" ) ) ,
21992199 binary_expr( "?left" , "NOT_LIKE" , "?right" ) ,
22002200 ) ,
2201+ rewrite(
2202+ "cast-as-date-to-datetrunc-replacer" ,
2203+ filter_replacer(
2204+ binary_expr(
2205+ cast_expr_explicit( column_expr( "?column" ) , DataType :: Date32 ) ,
2206+ "?op" ,
2207+ "?date_expr" ,
2208+ ) ,
2209+ "?alias_to_cube" ,
2210+ "?members" ,
2211+ "?filter_aliases" ,
2212+ ) ,
2213+ filter_replacer(
2214+ binary_expr(
2215+ self . fun_expr(
2216+ "DateTrunc" ,
2217+ vec![ literal_string( "day" ) , column_expr( "?column" ) ] ,
2218+ ) ,
2219+ "?op" ,
2220+ "?date_expr" ,
2221+ ) ,
2222+ "?alias_to_cube" ,
2223+ "?members" ,
2224+ "?filter_aliases" ,
2225+ ) ,
2226+ ) ,
22012227 transforming_rewrite(
22022228 "not-like-expr-to-like-negated-expr" ,
22032229 not_expr( like_expr(
You can’t perform that action at this time.
0 commit comments