Skip to content

Commit 2b2a8f3

Browse files
committed
added null test
Signed-off-by: Kenrick Yap <[email protected]>
1 parent 31ad2a4 commit 2b2a8f3

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

core/src/main/java/org/opensearch/sql/utils/JsonUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public class JsonUtils {
1616
*/
1717
public static ExprValue isValidJson(ExprValue jsonExprValue) {
1818
ObjectMapper objectMapper = new ObjectMapper();
19+
20+
if (jsonExprValue.isNull() || jsonExprValue.isMissing()) {
21+
return ExprValueUtils.LITERAL_FALSE;
22+
}
23+
1924
try {
2025
objectMapper.readTree(jsonExprValue.stringValue());
2126
return ExprValueUtils.LITERAL_TRUE;

integ-test/src/test/java/org/opensearch/sql/ppl/JsonFunctionsIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ public void test_not_json_valid() throws IOException {
5050
"source=%s | where not json_valid(json_string) | fields test_name",
5151
TEST_INDEX_JSON_TEST));
5252
verifySchema(result, schema("test_name", null, "string"));
53-
verifyDataRows(result, rows("json invalid object"));
53+
verifyDataRows(result, rows("json invalid object"), rows("json null"));
5454
}
5555
}

integ-test/src/test/resources/json_test.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010
{"test_name":"json empty string","json_string":""}
1111
{"index":{"_id":"5"}}
1212
{"test_name":"json invalid object", "json_string":"{\"invalid\":\"json\", \"string\"}"}
13+
{"index":{"_id":"6"}}
14+
{"test_name":"json null", "json_string":null}

0 commit comments

Comments
 (0)