This is an automated email from the ASF dual-hosted git repository.
jackie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new 24b50ed65f jsonPathString should return null instead of string literal
"null" (#10855)
24b50ed65f is described below
commit 24b50ed65f5ff1405479cd4136fda85ffa99f9c1
Author: Xiaobing <[email protected]>
AuthorDate: Wed Jun 7 13:05:10 2023 -0700
jsonPathString should return null instead of string literal "null" (#10855)
---
.../java/org/apache/pinot/common/function/scalar/JsonFunctions.java | 3 ++-
.../test/java/org/apache/pinot/common/function/JsonFunctionsTest.java | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git
a/pinot-common/src/main/java/org/apache/pinot/common/function/scalar/JsonFunctions.java
b/pinot-common/src/main/java/org/apache/pinot/common/function/scalar/JsonFunctions.java
index a81ec373b4..fa50cc6c48 100644
---
a/pinot-common/src/main/java/org/apache/pinot/common/function/scalar/JsonFunctions.java
+++
b/pinot-common/src/main/java/org/apache/pinot/common/function/scalar/JsonFunctions.java
@@ -128,6 +128,7 @@ public class JsonFunctions {
/**
* Extract from Json with path to String
*/
+ @Nullable
@ScalarFunction
public static String jsonPathString(Object object, String jsonPath)
throws JsonProcessingException {
@@ -135,7 +136,7 @@ public class JsonFunctions {
if (jsonValue instanceof String) {
return (String) jsonValue;
}
- return JsonUtils.objectToString(jsonValue);
+ return jsonValue == null ? null : JsonUtils.objectToString(jsonValue);
}
/**
diff --git
a/pinot-common/src/test/java/org/apache/pinot/common/function/JsonFunctionsTest.java
b/pinot-common/src/test/java/org/apache/pinot/common/function/JsonFunctionsTest.java
index ee98705f10..9ca44e7fc6 100644
---
a/pinot-common/src/test/java/org/apache/pinot/common/function/JsonFunctionsTest.java
+++
b/pinot-common/src/test/java/org/apache/pinot/common/function/JsonFunctionsTest.java
@@ -258,7 +258,7 @@ public class JsonFunctionsTest {
public static Object[][] jsonPathStringTestCases() {
return new Object[][]{
{ImmutableMap.of("foo", "x", "bar", ImmutableMap.of("foo", "y")),
"$.foo", "x"},
- {ImmutableMap.of("foo", "x", "bar", ImmutableMap.of("foo", "y")),
"$.qux", "null"},
+ {ImmutableMap.of("foo", "x", "bar", ImmutableMap.of("foo", "y")),
"$.qux", null},
{ImmutableMap.of("foo", "x", "bar", ImmutableMap.of("foo", "y")),
"$.bar", "{\"foo\":\"y\"}"},
};
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]