You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ja...@apache.org on 2023/06/07 20:05:17 UTC

[pinot] branch master updated: jsonPathString should return null instead of string literal "null" (#10855)

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 <61...@users.noreply.github.com>
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: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org