Jackie-Jiang commented on a change in pull request #7208:
URL: https://github.com/apache/pinot/pull/7208#discussion_r677714025
##########
File path:
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/JsonFunctions.java
##########
@@ -199,4 +207,47 @@ public static double jsonPathDouble(Object object, String
jsonPath, double defau
return defaultValue;
}
}
+
+ static class ArrayAwareJacksonJsonProvider extends JacksonJsonProvider {
+ @Override
+ public boolean isArray(Object obj) {
+ return (obj instanceof List) || (obj instanceof Object[]);
+ }
+
+ @Override
+ public Object getArrayIndex(Object obj, int idx) {
+ if (obj instanceof Object[]) {
+ return ((Object[]) obj)[idx];
+ }
+ return super.getArrayIndex(obj, idx);
+ }
+
+ @Override
+ public void setArrayIndex(Object obj, int index, Object newValue) {
Review comment:
This is probably not required?
##########
File path:
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/JsonFunctions.java
##########
@@ -109,12 +110,19 @@ public static Object jsonPath(Object object, String
jsonPath) {
if (object instanceof String) {
return convertObjectToArray(JsonPath.read((String) object, jsonPath));
}
- if (object instanceof Object[]) {
- return
convertObjectToArray(JsonPath.read(JsonUtils.objectToString(object), jsonPath));
- }
return convertObjectToArray(JsonPath.read(object, jsonPath));
}
+ @ScalarFunction
+ public static Object[] jsonPathArrayDefaultEmpty(Object object, String
jsonPath)
+ throws JsonProcessingException {
+ try {
+ return jsonPathArray(object, jsonPath);
+ } catch (Exception e) {
+ return new Object[]{};
Review comment:
(nit)
```suggestion
return new Object[0];
```
##########
File path:
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/JsonFunctions.java
##########
@@ -109,12 +110,19 @@ public static Object jsonPath(Object object, String
jsonPath) {
if (object instanceof String) {
return convertObjectToArray(JsonPath.read((String) object, jsonPath));
}
- if (object instanceof Object[]) {
- return
convertObjectToArray(JsonPath.read(JsonUtils.objectToString(object), jsonPath));
- }
return convertObjectToArray(JsonPath.read(object, jsonPath));
}
+ @ScalarFunction
+ public static Object[] jsonPathArrayDefaultEmpty(Object object, String
jsonPath)
+ throws JsonProcessingException {
Review comment:
It won't throw any exception
##########
File path:
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/JsonFunctions.java
##########
@@ -199,4 +207,47 @@ public static double jsonPathDouble(Object object, String
jsonPath, double defau
return defaultValue;
}
}
+
+ static class ArrayAwareJacksonJsonProvider extends JacksonJsonProvider {
Review comment:
Annotate with `VisibleForTesting`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]