77
88import static org .opensearch .sql .legacy .TestsConstants .TEST_INDEX_ACCOUNT ;
99import static org .opensearch .sql .legacy .TestsConstants .TEST_INDEX_BANK ;
10+ import static org .opensearch .sql .legacy .TestsConstants .TEST_INDEX_NESTED_SIMPLE ;
1011import static org .opensearch .sql .util .MatcherUtils .rows ;
12+ import static org .opensearch .sql .util .MatcherUtils .schema ;
1113import static org .opensearch .sql .util .MatcherUtils .verifyDataRows ;
14+ import static org .opensearch .sql .util .MatcherUtils .verifySchemaInOrder ;
1215
1316import java .io .IOException ;
1417import org .json .JSONObject ;
18+ import org .junit .Ignore ;
1519import org .junit .jupiter .api .Test ;
1620import org .opensearch .sql .ppl .StatsCommandIT ;
1721
@@ -21,6 +25,8 @@ public void init() throws Exception {
2125 super .init ();
2226 enableCalcite ();
2327 setQuerySizeLimit (2000 );
28+
29+ loadIndex (Index .NESTED_SIMPLE );
2430 }
2531
2632 @ Test
@@ -106,4 +112,60 @@ public void testPaginatingStatsForHeadFrom() throws IOException {
106112 resetQueryBucketSize ();
107113 }
108114 }
115+
116+ @ Test
117+ public void testNestedAggregation () throws IOException {
118+ JSONObject actual =
119+ executeQuery (
120+ String .format (
121+ "source=%s | stats count(address.area) as count_area, min(address.area) as"
122+ + " min_area, max(address.area) as max_area, avg(address.area) as avg_area,"
123+ + " avg(age) as avg_age" ,
124+ TEST_INDEX_NESTED_SIMPLE ));
125+ verifySchemaInOrder (
126+ actual ,
127+ isCalciteEnabled () ? schema ("count_area" , "bigint" ) : schema ("count_area" , "int" ),
128+ schema ("min_area" , "double" ),
129+ schema ("max_area" , "double" ),
130+ schema ("avg_area" , "double" ),
131+ schema ("avg_age" , "double" ));
132+ verifyDataRows (actual , rows (9 , 9.99 , 1000.99 , 300.11555555555555 , 25.2 ));
133+ }
134+
135+ @ Test
136+ public void testNestedAggregationBy () throws IOException {
137+ JSONObject actual =
138+ executeQuery (
139+ String .format (
140+ "source=%s | stats count(address.area) as count_area, min(address.area) as"
141+ + " min_area, max(address.area) as max_area, avg(address.area) as avg_area,"
142+ + " avg(age) as avg_age by name" ,
143+ TEST_INDEX_NESTED_SIMPLE ));
144+ verifySchemaInOrder (
145+ actual ,
146+ isCalciteEnabled () ? schema ("count_area" , "bigint" ) : schema ("count_area" , "int" ),
147+ schema ("min_area" , "double" ),
148+ schema ("max_area" , "double" ),
149+ schema ("avg_area" , "double" ),
150+ schema ("avg_age" , "double" ),
151+ schema ("name" , "string" ));
152+ verifyDataRows (
153+ actual ,
154+ rows (4 , 10.24 , 400.99 , 209.69 , 24 , "abbas" ),
155+ rows (0 , null , null , null , 19 , "andy" ),
156+ rows (2 , 9.99 , 1000.99 , 505.49 , 32 , "chen" ),
157+ rows (1 , 190.5 , 190.5 , 190.5 , 25 , "david" ),
158+ rows (2 , 231.01 , 429.79 , 330.4 , 26 , "peng" ));
159+ }
160+
161+ @ Ignore ("https://github.com/opensearch-project/sql/issues/3384" )
162+ public void testNestedAggregationBySpan () throws IOException {
163+ JSONObject actual =
164+ executeQuery (
165+ String .format (
166+ "source=%s | stats count(address.area) as count_area, min(address.area) as"
167+ + " min_area, max(address.area) as max_area, avg(address.area) as avg_area,"
168+ + " avg(age) as avg_age by span(age, 10)" ,
169+ TEST_INDEX_NESTED_SIMPLE ));
170+ }
109171}
0 commit comments