Jackie-Jiang commented on code in PR #12603:
URL: https://github.com/apache/pinot/pull/12603#discussion_r1520391643


##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/StringFunctions.java:
##########
@@ -831,4 +832,24 @@ public static boolean like(String inputStr, String 
likePatternStr) {
     String regexPatternStr = 
RegexpPatternConverterUtils.likeToRegexpLike(likePatternStr);
     return regexpLike(inputStr, regexPatternStr);
   }
+
+  /**
+   * Checks whether the input string can be parsed into a json node or not. 
Useful for scenarios where we want
+   * to filter out malformed json. In case of nulls, it is treated as valid 
json as in partial-upsert we might
+   * want to treat that column value as valid.
+   *
+   * @param inputStr Input string to test for valid json
+   */
+  @ScalarFunction
+  public static boolean isJson(String inputStr) {
+    try {
+      if (inputStr == null) {

Review Comment:
   The current semantic is quite confusing. I feel we should just not take 
`null` and the framework will simply return `null` when the input is `null`
   ```suggestion
     @ScalarFunction(names = {"isJson", "is_json"})
     public static boolean isJson(String inputStr) {
       try {
         JsonUtils.stringToJsonNode(inputStr);
         return true;
       } catch (Exception e) {
         return false;
       }
     }
   ```
   
   cc @ankitsultana 



-- 
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]

Reply via email to