Skip to content

Commit 606e346

Browse files
committed
Test pushing down case where there exists null values
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent d40c244 commit 606e346

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalcitePPLCaseFunctionIT.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.opensearch.sql.calcite.remote;
77

88
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK;
9+
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_STATE_COUNTRY_WITH_NULL;
910
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_WEBLOGS;
1011
import static org.opensearch.sql.util.MatcherUtils.closeTo;
1112
import static org.opensearch.sql.util.MatcherUtils.rows;
@@ -28,7 +29,7 @@ public void init() throws Exception {
2829

2930
loadIndex(Index.WEBLOG);
3031
loadIndex(Index.TIME_TEST_DATA);
31-
loadIndex(Index.TIME_TEST_DATA_WITH_NULL);
32+
loadIndex(Index.STATE_COUNTRY_WITH_NULL);
3233
loadIndex(Index.BANK);
3334
appendDataForBadResponse();
3435
}
@@ -442,4 +443,31 @@ public void testCaseCanBePushedDownAsCompositeRangeQuery() throws IOException {
442443
rows(5686.0, "hattiebond@netagy.com", "TN"),
443444
rows(16418.0, "elinorratliff@scentric.com", "WA"));
444445
}
446+
447+
@Test
448+
public void testCaseAggWithNullValues() throws IOException {
449+
JSONObject actual =
450+
executeQuery(
451+
String.format(
452+
"source=%s"
453+
+ "| eval age_category = case("
454+
+ " age < 20, 'teenager',"
455+
+ " age < 70, 'adult',"
456+
+ " age >= 70, 'senior'"
457+
+ " else 'unknown')"
458+
+ "| stats avg(age) by age_category",
459+
TEST_INDEX_STATE_COUNTRY_WITH_NULL));
460+
verifySchema(actual, schema("avg(age)", "double"), schema("age_category", "string"));
461+
// TODO: There is such discrepancy because range aggregations will ignore null values
462+
if (isPushdownDisabled()) {
463+
verifyDataRows(
464+
actual,
465+
rows(10, "teenager"),
466+
rows(25, "adult"),
467+
rows(70, "senior"),
468+
rows(null, "unknown"));
469+
} else {
470+
verifyDataRows(actual, rows(10, "teenager"), rows(25, "adult"), rows(70, "senior"));
471+
}
472+
}
445473
}

0 commit comments

Comments
 (0)