rubenada commented on code in PR #3394:
URL: https://github.com/apache/calcite/pull/3394#discussion_r1304254641


##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -352,54 +358,81 @@ public static String sha512(ByteString string)  {
     return DigestUtils.sha512Hex(string.getBytes());
   }
 
-  /** SQL {@code REGEXP_CONTAINS(value, regexp)} function.
-   * Throws a runtime exception for invalid regular expressions.*/
-  public static boolean regexpContains(String value, String regex) {
-    try {
-      // Uses java.util.regex as a standard for regex processing
-      // in Calcite instead of RE2 used by BigQuery/GoogleSQL
-      Pattern regexp = Pattern.compile(regex);
-      return regexp.matcher(value).find();
-    } catch (PatternSyntaxException ex) {
-      throw 
RESOURCE.invalidInputForRegexpContains(ex.getMessage().replace("\r\n", " ")
-          .replace("\n", " ").replace("\r", " ")).ex();
+  /** State for {@code REGEXP_CONTAINS}, {@code REGEXP_REPLACE}, {@code RLIKE}.
+   *
+   * <p>Marked deterministic so that the code generator instantiates one once
+   * per query, not once per row. */
+  @Deterministic
+  public static class RegexFunction {
+    private final LoadingCache<Ord<String>, Pattern> cache =
+        CacheBuilder.newBuilder().build(

Review Comment:
   It could be added into `CalciteSystemProperty`, which already contains some 
properties for several internal cache configs



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

Reply via email to