This is an automated email from the ASF dual-hosted git repository.

richardstartin 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 4fbda59  fix error handling and add covering tests in jsonPathArray 
tests (#8120)
4fbda59 is described below

commit 4fbda5968fa1f51cb1a569101a9dea2b7682332e
Author: Richard Startin <[email protected]>
AuthorDate: Thu Feb 3 19:19:45 2022 +0000

    fix error handling and add covering tests in jsonPathArray tests (#8120)
---
 .../org/apache/pinot/common/function/scalar/JsonFunctions.java    | 8 ++++++--
 .../java/org/apache/pinot/common/function/JsonFunctionsTest.java  | 3 +++
 2 files changed, 9 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 59fcff4..c109241 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
@@ -105,8 +105,12 @@ public class JsonFunctions {
 
   @ScalarFunction
   public static Object[] jsonPathArrayDefaultEmpty(Object object, String 
jsonPath) {
-    Object[] result = jsonPathArray(object, jsonPath);
-    return result == null ? EMPTY : result;
+    try {
+      Object[] result = object == null ? null : jsonPathArray(object, 
jsonPath);
+      return result == null ? EMPTY : result;
+    } catch (Exception e) {
+      return EMPTY;
+    }
   }
 
   private static Object[] convertObjectToArray(Object arrayObject) {
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 821364f..375e186 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
@@ -114,6 +114,9 @@ public class JsonFunctionsTest {
     assertEquals(JsonFunctions.jsonPathArray(jsonString, 
"$.subjects[*].grade"), new String[]{"A", "B"});
     assertEquals(JsonFunctions.jsonPathArray(jsonString, 
"$.subjects[*].homework_grades"),
         new Object[]{Arrays.asList(80, 85, 90, 95, 100), Arrays.asList(60, 65, 
70, 85, 90)});
+    assertEquals(JsonFunctions.jsonPathArrayDefaultEmpty(jsonString, null), 
new Object[0]);
+    assertEquals(JsonFunctions.jsonPathArrayDefaultEmpty(jsonString, "not 
json"), new Object[0]);
+    assertEquals(JsonFunctions.jsonPathArrayDefaultEmpty(jsonString, 
"$.subjects[*].missing"), new Object[0]);
   }
 
   @Test

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to