@@ -1417,3 +1417,106 @@ async fn wrapper_agg_dimension_over_limit() {
14171417 . sql
14181418 . contains( "\" ungrouped\" : true" ) ) ;
14191419}
1420+
1421+ /// Aggregation with falsy filter should NOT get pushed to CubeScan with limit=0
1422+ /// This test currently produces WrappedSelect with WHERE FALSE, which is OK for our purposes
1423+ #[ tokio:: test]
1424+ async fn select_agg_where_false ( ) {
1425+ if !Rewriter :: sql_push_down_enabled ( ) {
1426+ return ;
1427+ }
1428+ init_testing_logger ( ) ;
1429+
1430+ let query_plan = convert_select_to_query_plan (
1431+ "SELECT SUM(sumPrice) FROM KibanaSampleDataEcommerce WHERE 1 = 0" . to_string ( ) ,
1432+ DatabaseProtocol :: PostgreSQL ,
1433+ )
1434+ . await ;
1435+
1436+ let physical_plan = query_plan. as_physical_plan ( ) . await . unwrap ( ) ;
1437+ println ! (
1438+ "Physical plan: {}" ,
1439+ displayable( physical_plan. as_ref( ) ) . indent( )
1440+ ) ;
1441+
1442+ let logical_plan = query_plan. as_logical_plan ( ) ;
1443+ assert_eq ! (
1444+ logical_plan. find_cube_scan( ) . request,
1445+ V1LoadRequestQuery {
1446+ measures: Some ( vec![ ] ) ,
1447+ segments: Some ( vec![ ] ) ,
1448+ dimensions: Some ( vec![ ] ) ,
1449+ order: Some ( vec![ ] ) ,
1450+ limit: None ,
1451+ ungrouped: Some ( true ) ,
1452+ ..Default :: default ( )
1453+ }
1454+ ) ;
1455+
1456+ let sql = logical_plan
1457+ . find_cube_scan_wrapper ( )
1458+ . wrapped_sql
1459+ . unwrap ( )
1460+ . sql ;
1461+
1462+ // Final query uses grouped query to Cube.js with WHERE FALSE, but without LIMIT 0
1463+ assert ! ( !sql. contains( "\" ungrouped\" :" ) ) ;
1464+ assert ! ( sql. contains( r#"\"expr\":\"FALSE\""# ) ) ;
1465+ assert ! ( sql. contains( r#""limit": 50000"# ) ) ;
1466+ }
1467+
1468+ /// Aggregation(dimension) with falsy filter should NOT get pushed to CubeScan with limit=0
1469+ /// This test currently produces WrappedSelect with WHERE FALSE, which is OK for our purposes
1470+ #[ tokio:: test]
1471+ async fn wrapper_dimension_agg_where_false ( ) {
1472+ if !Rewriter :: sql_push_down_enabled ( ) {
1473+ return ;
1474+ }
1475+ init_testing_logger ( ) ;
1476+
1477+ let query_plan = convert_select_to_query_plan (
1478+ // language=PostgreSQL
1479+ r#"
1480+ SELECT
1481+ MAX(customer_gender)
1482+ FROM
1483+ KibanaSampleDataEcommerce
1484+ WHERE 1 = 0
1485+ "#
1486+ . to_string ( ) ,
1487+ DatabaseProtocol :: PostgreSQL ,
1488+ )
1489+ . await ;
1490+
1491+ let physical_plan = query_plan. as_physical_plan ( ) . await . unwrap ( ) ;
1492+ println ! (
1493+ "Physical plan: {}" ,
1494+ displayable( physical_plan. as_ref( ) ) . indent( )
1495+ ) ;
1496+
1497+ let logical_plan = query_plan. as_logical_plan ( ) ;
1498+ assert_eq ! (
1499+ logical_plan. find_cube_scan( ) . request,
1500+ V1LoadRequestQuery {
1501+ measures: Some ( vec![ ] ) ,
1502+ dimensions: Some ( vec![ ] ) ,
1503+ segments: Some ( vec![ ] ) ,
1504+ order: Some ( vec![ ] ) ,
1505+ limit: None ,
1506+ ungrouped: Some ( true ) ,
1507+ ..Default :: default ( )
1508+ }
1509+ ) ;
1510+
1511+ let sql = logical_plan
1512+ . find_cube_scan_wrapper ( )
1513+ . wrapped_sql
1514+ . unwrap ( )
1515+ . sql ;
1516+
1517+ // Final query uses grouped query to Cube.js with WHERE FALSE, but without LIMIT 0
1518+ assert ! ( !sql. contains( "\" ungrouped\" :" ) ) ;
1519+ assert ! ( sql. contains( r#"\"expr\":\"FALSE\""# ) ) ;
1520+ assert ! ( !sql. contains( r#""limit""# ) ) ;
1521+ assert ! ( sql. contains( "LIMIT 50000" ) ) ;
1522+ }
0 commit comments