From fbc54bc59f1e54b89d14dff96b2578772f2647c5 Mon Sep 17 00:00:00 2001 From: Kenrick Yap Date: Fri, 10 Jan 2025 10:37:08 -0800 Subject: [PATCH] addressed PR comments Signed-off-by: Kenrick Yap --- .../expression/json/JsonFunctionsTest.java | 3 +++ docs/user/ppl/functions/json.rst | 21 ++++++++++--------- doctest/test_data/json_test.json | 1 + .../opensearch/sql/ppl/JsonFunctionsIT.java | 1 + integ-test/src/test/resources/json_test.json | 2 ++ 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/core/src/test/java/org/opensearch/sql/expression/json/JsonFunctionsTest.java b/core/src/test/java/org/opensearch/sql/expression/json/JsonFunctionsTest.java index 2e8ece2817..e374841e7f 100644 --- a/core/src/test/java/org/opensearch/sql/expression/json/JsonFunctionsTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/json/JsonFunctionsTest.java @@ -19,6 +19,8 @@ @ExtendWith(MockitoExtension.class) public class JsonFunctionsTest { + private static final ExprValue JsonNestedObject = + ExprValueUtils.stringValue("{\"a\":\"1\",\"b\":{\"c\":\"2\",\"d\":\"3\"}}"); private static final ExprValue JsonObject = ExprValueUtils.stringValue("{\"a\":\"1\",\"b\":\"2\"}"); private static final ExprValue JsonArray = ExprValueUtils.stringValue("[1, 2, 3, 4]"); @@ -36,6 +38,7 @@ public void json_valid_returns_false() { @Test public void json_valid_returns_true() { + assertEquals(LITERAL_TRUE, execute(JsonNestedObject)); assertEquals(LITERAL_TRUE, execute(JsonObject)); assertEquals(LITERAL_TRUE, execute(JsonArray)); assertEquals(LITERAL_TRUE, execute(JsonScalarString)); diff --git a/docs/user/ppl/functions/json.rst b/docs/user/ppl/functions/json.rst index a69101300b..ce3d1a4c76 100644 --- a/docs/user/ppl/functions/json.rst +++ b/docs/user/ppl/functions/json.rst @@ -1,5 +1,5 @@ ==================== -IP Address Functions +JSON Functions ==================== .. rubric:: Table of contents @@ -24,12 +24,13 @@ Example:: > source=json_test | eval is_valid = json_valid(json_string) | fields test_name, json_string, is_valid fetched rows / total rows = 4/4 - +---------------------+------------------------------+----------+ - | test_name | json_string | is_valid | - |---------------------|------------------------------|----------| - | json object | {"a":"1","b":"2"} | True | - | json array | [1, 2, 3, 4] | True | - | json scalar string | "abc" | True | - | json empty string | | True | - | json invalid object | {"invalid":"json", "string"} | False | - +---------------------+------------------------------+----------+ + +---------------------+---------------------------------+----------+ + | test_name | json_string | is_valid | + |---------------------|---------------------------------|----------| + | json nested object | {"a":"1","b":{"c":"2","d":"3"}} | True | + | json object | {"a":"1","b":"2"} | True | + | json array | [1, 2, 3, 4] | True | + | json scalar string | "abc" | True | + | json empty string | | True | + | json invalid object | {"invalid":"json", "string"} | False | + +---------------------+---------------------------------+----------+ diff --git a/doctest/test_data/json_test.json b/doctest/test_data/json_test.json index 2da491675e..7494fc4aa9 100644 --- a/doctest/test_data/json_test.json +++ b/doctest/test_data/json_test.json @@ -1,3 +1,4 @@ +{"test_name":"json nested object", "json_string":"{\"a\":\"1\",\"b\":{\"c\":\"2\",\"d\":\"3\"}}"} {"test_name":"json object", "json_string":"{\"a\":\"1\",\"b\":\"2\"}"} {"test_name":"json array", "json_string":"[1, 2, 3, 4]"} {"test_name":"json scalar string", "json_string":"\"abc\""} diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/JsonFunctionsIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/JsonFunctionsIT.java index 501ef9448e..f852a97d48 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/JsonFunctionsIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/JsonFunctionsIT.java @@ -33,6 +33,7 @@ public void test_json_valid() throws IOException { verifySchema(result, schema("test_name", null, "string")); verifyDataRows( result, + rows("json nested object"), rows("json object"), rows("json array"), rows("json scalar string"), diff --git a/integ-test/src/test/resources/json_test.json b/integ-test/src/test/resources/json_test.json index e198eb7c43..badb4f4f6e 100644 --- a/integ-test/src/test/resources/json_test.json +++ b/integ-test/src/test/resources/json_test.json @@ -1,3 +1,5 @@ +{"index":{"_id":"0"}} +{"test_name":"json nested object", "json_string":"{\"a\":\"1\",\"b\":{\"c\":\"2\",\"d\":\"3\"}}"} {"index":{"_id":"1"}} {"test_name":"json object", "json_string":"{\"a\":\"1\",\"b\":\"2\"}"} {"index":{"_id":"2"}}