tanclary commented on code in PR #3147:
URL: https://github.com/apache/calcite/pull/3147#discussion_r1286109761


##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -562,6 +564,91 @@ public static List<ByteString> split(ByteString s, 
ByteString delimiter) {
     }
   }
 
+  public static @Nullable Boolean containsSubstr(@Nullable Object @Nullable [] 
s0, String s1) {
+    // If s0 has null arguments, it should return TRUE if substring is found, 
otherwise NULL
+    boolean nullFlag = false;
+    if (s0 == null) {
+      return false;
+    }
+    for (Object obj : s0) {
+      if (obj == null) {
+        nullFlag = true;
+      } else if (obj instanceof Object[]) {
+        return containsSubstr((Object[]) obj, s1);
+      } else if (obj instanceof ArrayList) {
+        return containsSubstr((List) obj, s1);
+      } else if (normalize(obj.toString()).contains(normalize(s1))) {
+        return true;
+      }
+    }
+    return nullFlag ? null : false;
+  }
+
+  public static @Nullable Boolean containsSubstr(List s0, String s1) {
+    // If s0 has null arguments, it should return TRUE if substring is found, 
otherwise NULL
+    boolean nullFlag = false;
+    for (Object item : s0) {
+      if (item == null) {
+        nullFlag = true;
+      }
+      if (item != null && containsSubstr(item, s1)) {
+        return true;
+      }
+    }
+    return nullFlag ? null : false;
+  }
+
+  public static @Nullable Boolean containsSubstr(String s0, String s1, String 
s2) {
+    // The third argument specifies the json_scope, either keys, values, or 
both
+    LinkedHashMap<String, String> map = (LinkedHashMap) 
JsonFunctions.dejsonize(s0);
+    Set<String> keys = map.keySet();
+    Collection<String> values = map.values();
+    if (s2.equals("JSON_KEYS")) {

Review Comment:
   Done



##########
core/src/main/java/org/apache/calcite/sql/SqlKind.java:
##########
@@ -839,6 +839,8 @@ public enum SqlKind {
    * TABLE(udx(CURSOR(SELECT ...), x, y, z))</code>. */
   CURSOR,
 
+  CONTAINS_SUBSTR,

Review Comment:
   Done



-- 
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-unsubscr...@calcite.apache.org

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

Reply via email to