66package org .opensearch .sql .calcite .remote ;
77
88import static org .opensearch .sql .legacy .TestsConstants .TEST_INDEX_BANK ;
9+ import static org .opensearch .sql .legacy .TestsConstants .TEST_INDEX_OTEL_LOGS ;
910import static org .opensearch .sql .legacy .TestsConstants .TEST_INDEX_STATE_COUNTRY_WITH_NULL ;
1011import static org .opensearch .sql .legacy .TestsConstants .TEST_INDEX_WEBLOGS ;
1112import static org .opensearch .sql .util .MatcherUtils .closeTo ;
1213import static org .opensearch .sql .util .MatcherUtils .rows ;
1314import static org .opensearch .sql .util .MatcherUtils .schema ;
1415import static org .opensearch .sql .util .MatcherUtils .verifyDataRows ;
16+ import static org .opensearch .sql .util .MatcherUtils .verifyNumOfRows ;
1517import static org .opensearch .sql .util .MatcherUtils .verifySchema ;
1618
1719import java .io .IOException ;
@@ -31,6 +33,7 @@ public void init() throws Exception {
3133 loadIndex (Index .TIME_TEST_DATA );
3234 loadIndex (Index .STATE_COUNTRY_WITH_NULL );
3335 loadIndex (Index .BANK );
36+ loadIndex (Index .OTELLOGS );
3437 appendDataForBadResponse ();
3538 }
3639
@@ -470,4 +473,46 @@ public void testCaseAggWithNullValues() throws IOException {
470473 verifyDataRows (actual , rows (10 , "teenager" ), rows (25 , "adult" ), rows (70 , "senior" ));
471474 }
472475 }
476+
477+ @ Test
478+ public void testNestedCaseAggWithAutoDateHistogram () throws IOException {
479+ JSONObject actual1 =
480+ executeQuery (
481+ String .format (
482+ "source=%s | bin @timestamp bins=2 | eval severity_range = case(severityNumber <"
483+ + " 16, 'minor' else 'severe') | stats avg(severityNumber), count() by"
484+ + " @timestamp, severity_range, flags" ,
485+ TEST_INDEX_OTEL_LOGS ));
486+ verifySchema (
487+ actual1 ,
488+ schema ("avg(severityNumber)" , "double" ),
489+ schema ("count()" , "bigint" ),
490+ schema ("@timestamp" , "timestamp" ),
491+ schema ("severity_range" , "string" ),
492+ schema ("flags" , "bigint" ));
493+
494+ verifyDataRows (
495+ actual1 ,
496+ rows (8.85 , 20 , "2024-01-15 10:30:02" , "minor" , 0 ),
497+ rows (20 , 9 , "2024-01-15 10:30:02" , "severe" , 0 ),
498+ rows (9 , 1 , "2024-01-15 10:30:00" , "minor" , 1 ),
499+ rows (17 , 1 , "2024-01-15 10:30:00" , "severe" , 1 ),
500+ rows (1 , 1 , "2024-01-15 10:30:05" , "minor" , 1 ));
501+
502+ JSONObject actual2 =
503+ executeQuery (
504+ String .format (
505+ "source=%s | bin @timestamp bins=100 | eval severity_range = case(severityNumber <"
506+ + " 16, 'minor' else 'severe') | stats avg(severityNumber), count() by"
507+ + " @timestamp, severity_range, flags" ,
508+ TEST_INDEX_OTEL_LOGS ));
509+ verifySchema (
510+ actual2 ,
511+ schema ("avg(severityNumber)" , "double" ),
512+ schema ("count()" , "bigint" ),
513+ schema ("@timestamp" , "timestamp" ),
514+ schema ("severity_range" , "string" ),
515+ schema ("flags" , "bigint" ));
516+ verifyNumOfRows (actual2 , 32 );
517+ }
473518}
0 commit comments