Skip to content

Commit 6a96118

Browse files
committed
Redefine type checkers of isnull, isnotnull, and ispresent to IGNORE
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent d758163 commit 6a96118

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

core/src/main/java/org/opensearch/sql/expression/function/PPLFuncImpTable.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,9 +727,7 @@ void populate() {
727727
registerOperator(SIGNUM, SqlStdOperatorTable.SIGN);
728728
registerOperator(SIN, SqlStdOperatorTable.SIN);
729729
registerOperator(CBRT, SqlStdOperatorTable.CBRT);
730-
registerOperator(IS_NOT_NULL, SqlStdOperatorTable.IS_NOT_NULL);
731-
registerOperator(IS_PRESENT, SqlStdOperatorTable.IS_NOT_NULL);
732-
registerOperator(IS_NULL, SqlStdOperatorTable.IS_NULL);
730+
733731
registerOperator(IFNULL, SqlStdOperatorTable.COALESCE);
734732
registerOperator(EARLIEST, PPLBuiltinOperators.EARLIEST);
735733
registerOperator(LATEST, PPLBuiltinOperators.LATEST);
@@ -1040,6 +1038,20 @@ void populate() {
10401038
builder.makeLiteral(" "),
10411039
arg))),
10421040
PPLTypeChecker.family(SqlTypeFamily.ANY));
1041+
// Re-define the type checker for is not null, is present, and is null since their original
1042+
// type checker ANY isn't compatible with struct types.
1043+
register(
1044+
IS_NOT_NULL,
1045+
(builder, args) -> builder.makeCall(SqlStdOperatorTable.IS_NOT_NULL, args),
1046+
PPLTypeChecker.family(SqlTypeFamily.IGNORE));
1047+
register(
1048+
IS_PRESENT,
1049+
(builder, args) -> builder.makeCall(SqlStdOperatorTable.IS_NOT_NULL, args),
1050+
PPLTypeChecker.family(SqlTypeFamily.IGNORE));
1051+
register(
1052+
IS_NULL,
1053+
(builder, args) -> builder.makeCall(SqlStdOperatorTable.IS_NULL, args),
1054+
PPLTypeChecker.family(SqlTypeFamily.IGNORE));
10431055
register(
10441056
LIKE,
10451057
(FunctionImp2)

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public void init() throws Exception {
2424
loadIndex(Index.STATE_COUNTRY);
2525
loadIndex(Index.STATE_COUNTRY_WITH_NULL);
2626
loadIndex(Index.CALCS);
27+
loadIndex(Index.NESTED_WITHOUT_ARRAYS);
28+
loadIndex(Index.BIG5);
2729
Request request1 =
2830
new Request("PUT", "/" + TEST_INDEX_STATE_COUNTRY_WITH_NULL + "/_doc/7?refresh=true");
2931
request1.setJsonEntity(
@@ -47,6 +49,11 @@ public void testIsNull() throws IOException {
4749
verifySchema(actual, schema("age", "int"));
4850

4951
verifyDataRows(actual, rows(10));
52+
53+
// Test isNull on struct objects
54+
actual = executeQuery("source=big5 | where isnull(aws) | fields aws");
55+
verifySchema(actual, schema("aws", "struct"));
56+
verifyNumOfRows(actual, 0);
5057
}
5158

5259
@Test
@@ -68,6 +75,11 @@ public void testIsNotNull() throws IOException {
6875
rows("Kevin"),
6976
rows(" "),
7077
rows(""));
78+
79+
// Test isNotNull on struct objects
80+
actual = executeQuery("source=big5 | where isnotnull(aws) | fields aws");
81+
verifySchema(actual, schema("aws", "struct"));
82+
verifyNumOfRows(actual, 1);
7183
}
7284

7385
@Test

0 commit comments

Comments
 (0)