You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2021/11/23 12:38:05 UTC

[GitHub] [pinot] richardstartin commented on a change in pull request #7819: prevent exceptions from being thrown when jsonpaths don't match inputs

richardstartin commented on a change in pull request #7819:
URL: https://github.com/apache/pinot/pull/7819#discussion_r755082361



##########
File path: pinot-common/src/main/java/org/apache/pinot/common/function/scalar/JsonFunctions.java
##########
@@ -149,50 +159,45 @@ public static String jsonPathString(Object object, String jsonPath, String defau
    */
   @ScalarFunction
   public static long jsonPathLong(Object object, String jsonPath) {
-    final Object jsonValue = jsonPath(object, jsonPath);
-    if (jsonValue == null) {
-      return Long.MIN_VALUE;
-    }
-    if (jsonValue instanceof Number) {
-      return ((Number) jsonValue).longValue();
-    }
-    return Long.parseLong(jsonValue.toString());
+    return jsonPathLong(object, jsonPath, Long.MIN_VALUE);
   }
 
   /**
    * Extract from Json with path to Long
    */
   @ScalarFunction
   public static long jsonPathLong(Object object, String jsonPath, long defaultValue) {
-    try {
-      return jsonPathLong(object, jsonPath);
-    } catch (Exception e) {
+    final Object jsonValue = jsonPath(object, jsonPath);
+    if (jsonValue == null) {
       return defaultValue;
     }
+    if (jsonValue instanceof Number) {
+      return ((Number) jsonValue).longValue();
+    }
+    return Long.parseLong(jsonValue.toString());
   }
 
   /**
    * Extract from Json with path to Double
    */
   @ScalarFunction
   public static double jsonPathDouble(Object object, String jsonPath) {
-    final Object jsonValue = jsonPath(object, jsonPath);
-    if (jsonValue instanceof Number) {
-      return ((Number) jsonValue).doubleValue();
-    }
-    return Double.parseDouble(jsonValue.toString());
+    return jsonPathDouble(object, jsonPath, Double.NaN);

Review comment:
       this is a behaviour change - it used to throw on missing paths (which I believe was unintended) and now returns `NaN`




-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org