chucheng92 commented on code in PR #3394:
URL: https://github.com/apache/calcite/pull/3394#discussion_r1303735179
##########
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:
Can we add maximumSize and expire strategy (add a extra config to control
it)? I'm asking this because in the production environment, users like to use
functions such as regular expressions very much, and there will be many such
functions in one query or parallel queries, the cache may increase very quickly.
--
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]