ankitsultana commented on code in PR #12603:
URL: https://github.com/apache/pinot/pull/12603#discussion_r1518502147
##########
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:
nit: Semantically speaking, `null` in databases means "unknown" or
"missing", and hence one might expect `isJson` to return false for null.
To address this, we could consider adding a two argument variant of this
```
public static boolean isJson(String inputStr, boolean acceptNull) {
try {
if (inputStr == null) {
return acceptNull;
}
...
}
}
```
--
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]