55
66package org .opensearch .sql .calcite .remote ;
77
8- import static org .junit .jupiter .api .Assertions .assertTrue ;
98import static org .opensearch .sql .legacy .TestsConstants .TEST_INDEX_BANK ;
109import static org .opensearch .sql .legacy .TestsConstants .TEST_INDEX_WEBLOGS ;
1110import static org .opensearch .sql .util .MatcherUtils .closeTo ;
@@ -292,7 +291,7 @@ public void testCaseCanBePushedDownAsRangeQuery() throws IOException {
292291 verifyDataRows (
293292 actual3 ,
294293 rows (32838.0 , "u30" , "high" ),
295- rows (8761.333333333334 , "u40" , "medium" ),
294+ closeTo (8761.333333333334 , "u40" , "medium" ),
296295 rows (42617.0 , "u40" , "high" ));
297296
298297 // 1.4 Range - Metric (With null & discontinuous ranges)
@@ -303,11 +302,20 @@ public void testCaseCanBePushedDownAsRangeQuery() throws IOException {
303302 + " >= 80, '30-40 or >=80') | stats avg(balance) by age_range" ,
304303 TEST_INDEX_BANK ));
305304 verifySchema (actual4 , schema ("avg(balance)" , "double" ), schema ("age_range" , "string" ));
306- verifyDataRows (
307- actual4 ,
308- closeTo (32838.0 , "u30" ),
309- closeTo (30497.0 , "null" ),
310- closeTo (20881.333333333332 , "30-40 or >=80" ));
305+ // There's such a discrepancy because null cannot be the key for a range query
306+ if (isPushdownDisabled ()) {
307+ verifyDataRows (
308+ actual4 ,
309+ rows (32838.0 , "u30" ),
310+ rows (30497.0 , null ),
311+ closeTo (20881.333333333332 , "30-40 or >=80" ));
312+ } else {
313+ verifyDataRows (
314+ actual4 ,
315+ rows (32838.0 , "u30" ),
316+ rows (30497.0 , "null" ),
317+ closeTo (20881.333333333332 , "30-40 or >=80" ));
318+ }
311319
312320 // 1.5 Should not be pushed because the range is not closed-open
313321 JSONObject actual5 =
@@ -318,7 +326,10 @@ public void testCaseCanBePushedDownAsRangeQuery() throws IOException {
318326 TEST_INDEX_BANK ));
319327 verifySchema (actual5 , schema ("avg_age" , "double" ), schema ("age_range" , "string" ));
320328 verifyDataRows (actual5 , rows (35.0 , "u40" ), rows (28.0 , "u30" ));
329+ }
321330
331+ @ Test
332+ public void testCaseCanBePushedDownAsCompositeRangeQuery () throws IOException {
322333 // CASE 2: Composite - Range - Metric
323334 // 2.1 Composite (term) - Range - Metric
324335 JSONObject actual6 =
@@ -347,18 +358,19 @@ public void testCaseCanBePushedDownAsRangeQuery() throws IOException {
347358 executeQuery (
348359 "source=opensearch-sql_test_index_time_data | eval value_range = case(value < 7000,"
349360 + " 'small' else 'large') | stats avg(value) by value_range, span(@timestamp,"
350- + " 1h )" );
361+ + " 1month )" );
351362 verifySchema (
352363 actual7 ,
353364 schema ("avg(value)" , "double" ),
354- schema ("span(@timestamp,1h )" , "timestamp" ),
365+ schema ("span(@timestamp,1month )" , "timestamp" ),
355366 schema ("value_range" , "string" ));
356- // Verify we have results with both small and large ranges and timestamps
357- assertTrue (actual7 .getJSONArray ("datarows" ).length () == 100 );
358- // Verify some sample rows to check data correctness
359- String resultStr = actual7 .toString ();
360- assertTrue (resultStr .contains ("small" ) && resultStr .contains ("large" ));
361- assertTrue (resultStr .contains ("2025-07-28" ) && resultStr .contains ("2025-07-29" ));
367+
368+ verifyDataRows (
369+ actual7 ,
370+ closeTo (6642.521739130435 , "2025-07-01 00:00:00" , "small" ),
371+ closeTo (8381.917808219177 , "2025-07-01 00:00:00" , "large" ),
372+ rows (6489.0 , "2025-08-01 00:00:00" , "small" ),
373+ rows (8375.0 , "2025-08-01 00:00:00" , "large" ));
362374
363375 // 2.3 Composite(2 fields) - Range - Metric (with count)
364376 JSONObject actual8 =
0 commit comments