julianhyde commented on code in PR #3394:
URL: https://github.com/apache/calcite/pull/3394#discussion_r1304783880
##########
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:
In a later commit I removed `class RegexFunction`, but the comments are
still applicable.
The caches are within a single function object and are not static. Therefore
the cache only holds for the duration of a particular query, there is a
separate cache for each call site if a function is used multiple times in the
same query.
I agree that we need a maximum size, in case a query of 100 million rows
generates a unique regex for every row. But I don't think we need a time-based
expiration strategy.
--
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]