File tree Expand file tree Collapse file tree 2 files changed +80
-0
lines changed
rust/cubesql/cubesql/src/compile Expand file tree Collapse file tree 2 files changed +80
-0
lines changed Original file line number Diff line number Diff line change @@ -16103,4 +16103,44 @@ ORDER BY \"COUNT(count)\" DESC"
1610316103 }
1610416104 )
1610516105 }
16106+
16107+ #[tokio::test]
16108+ async fn test_thoughtspot_nullif_measure_dimension() {
16109+ init_logger();
16110+
16111+ let logical_plan = convert_select_to_query_plan(
16112+ r#"
16113+ SELECT
16114+ NULLIF(CAST("ta_1"."taxful_total_price" AS FLOAT8), 0.0) "ca_1",
16115+ NULLIF(CAST("ta_1"."count" AS FLOAT8), 0.0) "ca_2"
16116+ FROM KibanaSampleDataEcommerce "ta_1"
16117+ GROUP BY
16118+ "ca_1",
16119+ "ca_2"
16120+ ORDER BY
16121+ "ca_1" ASC,
16122+ "ca_2" ASC
16123+ "#
16124+ .to_string(),
16125+ DatabaseProtocol::PostgreSQL,
16126+ )
16127+ .await
16128+ .as_logical_plan();
16129+
16130+ assert_eq!(
16131+ logical_plan.find_cube_scan().request,
16132+ V1LoadRequestQuery {
16133+ measures: Some(vec!["KibanaSampleDataEcommerce.count".to_string()]),
16134+ dimensions: Some(vec![
16135+ "KibanaSampleDataEcommerce.taxful_total_price".to_string()
16136+ ]),
16137+ segments: Some(vec![]),
16138+ time_dimensions: None,
16139+ order: None,
16140+ limit: None,
16141+ offset: None,
16142+ filters: None,
16143+ }
16144+ )
16145+ }
1610616146}
Original file line number Diff line number Diff line change @@ -2165,6 +2165,18 @@ impl RewriteRules for SplitRules {
21652165 ) ,
21662166 inner_aggregate_split_replacer( "?expr" , "?cube" ) ,
21672167 ) ,
2168+ // NullIf
2169+ rewrite(
2170+ "split-push-down-nullif-inner-replacer" ,
2171+ inner_aggregate_split_replacer(
2172+ fun_expr(
2173+ "NullIf" ,
2174+ vec![ "?expr" . to_string( ) , literal_expr( "?literal" ) ] ,
2175+ ) ,
2176+ "?cube" ,
2177+ ) ,
2178+ inner_aggregate_split_replacer( "?expr" , "?cube" ) ,
2179+ ) ,
21682180 // IS NULL, IS NOT NULL
21692181 rewrite(
21702182 "split-push-down-is-null-inner-replacer" ,
@@ -3781,6 +3793,34 @@ impl RewriteRules for SplitRules {
37813793 )
37823794 . into_iter ( ) ,
37833795 ) ;
3796+ // NullIf
3797+ rules. extend (
3798+ self . outer_aggr_group_expr_aggr_combinator_rewrite (
3799+ "split-push-down-nullif-replacer" ,
3800+ |split_replacer| {
3801+ split_replacer (
3802+ fun_expr ( "NullIf" , vec ! [ "?expr" . to_string( ) , literal_expr( "?else" ) ] ) ,
3803+ "?cube" ,
3804+ )
3805+ } ,
3806+ |_| vec ! [ ] ,
3807+ |split_replacer| {
3808+ fun_expr (
3809+ "NullIf" ,
3810+ vec ! [
3811+ split_replacer( "?expr" . to_string( ) , "?cube" ) ,
3812+ literal_expr( "?else" ) ,
3813+ ] ,
3814+ )
3815+ } ,
3816+ |_, _| true ,
3817+ false ,
3818+ true ,
3819+ true ,
3820+ Some ( vec ! [ ( "?expr" , column_expr( "?column" ) ) ] ) ,
3821+ )
3822+ . into_iter ( ) ,
3823+ ) ;
37843824 // IS NULL
37853825 rules. extend (
37863826 self . outer_aggr_group_expr_aggr_combinator_rewrite (
You can’t perform that action at this time.
0 commit comments