You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "raminqaf (via GitHub)" <gi...@apache.org> on 2026/06/02 08:09:32 UTC
[PR] [FLINK-39651][table] REGEXP plan-time validation and hot-path log cleanup [flink]
raminqaf opened a new pull request, #28292:
URL: https://github.com/apache/flink/pull/28292
## What is the purpose of the change
`REGEXP` does not validate literal regex patterns at planning time. When the regex is a string literal that fails `Pattern.compile`, the predicate logged an `ERROR` stack trace per record on the hot path (for example `... WHERE payload REGEXP '('`). This PR surfaces the failure as a `ValidationException` during type inference and removes the per-record log spam.
This is a sub-task of the FLINK-39648 umbrella, following the pattern already established for `REGEXP_EXTRACT` (FLINK-39649) and `REGEXP_REPLACE` (FLINK-39650). It reuses the shared `StrategyUtils.validateLiteralPattern` helper introduced by those sub-tasks.
## Brief change log
- Drop the hot-path `LOG.error` in `SqlFunctionUtils.regExp`; catch `PatternSyntaxException` and return false. The pattern was already looked up through `REGEXP_PATTERN_CACHE`.
- Migrate `BuiltInFunctionDefinitions.REGEXP` to `name("REGEXP")` + `runtimeProvided()`. Remove the legacy `FlinkSqlOperatorTable.REGEXP` entry, the `DirectConvertRule` mapping, and the `case REGEXP` arm in `StringCallGen`. Add a routing arm in `ExprCodeGenerator`'s `BridgingSqlFunction` block.
- Add `RegexpInputTypeStrategy` that validates 2 STRING args and the literal regex via `StrategyUtils.validateLiteralPattern`. Wire it through `SpecificInputTypeStrategies.REGEXP`.
## Verifying this change
This change added tests and can be verified as follows:
- New `RegexpInputTypeStrategyTest` covers four branches: non-literal regex defers, valid literal compiles, null literal is deferred, invalid literal fails at plan time.
- New `regexpTestCases()` in `RegexpFunctionsITCase` covers runtime behavior end-to-end (literal match/no-match, null input, column-ref invalid, function-call regex) plus a plan-time validation case via Table API and SQL.
- Existing `ScalarFunctionsTest`, `AsyncCalcSplitRuleTest`, and `AsyncCalcITCase` regress the operator.
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): no
- The public API, i.e., is any changed class annotated with `@Public(Evolving)`: no
- The serializers: no
- The runtime per-record code paths (performance sensitive): yes (removes per-record `LOG.error` in `regExp` on invalid patterns)
- Anything that affects deployment or recovery: no
- The S3 file system connector: no
## Documentation
- Does this pull request introduce a new feature? no
- If yes, how is the feature documented? not applicable
---
##### Was generative AI tooling used to co-author this PR?
- [x] Yes (please specify the tool below)
Generated-by: Opus 4.8
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39651][table] REGEXP plan-time validation and hot-path log cleanup [flink]
Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #28292:
URL: https://github.com/apache/flink/pull/28292#issuecomment-4600179768
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "91c4d976d4ded0a310674aa6d4218f30f693cc9f",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "91c4d976d4ded0a310674aa6d4218f30f693cc9f",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 91c4d976d4ded0a310674aa6d4218f30f693cc9f UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run azure` re-run the last Azure build
</details>
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39651][table] REGEXP plan-time validation and hot-path log cleanup [flink]
Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #28292:
URL: https://github.com/apache/flink/pull/28292#discussion_r3340135237
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/SqlFunctionUtils.java:
##########
@@ -1015,14 +1015,19 @@ public static Integer hashCode(String str) {
return Math.abs(str.hashCode());
}
+ /**
+ * Returns whether {@code s} contains a match for the regular expression {@code regex}. Literal
+ * regexes are validated at planning time by the input type strategy.
+ */
public static Boolean regExp(String s, String regex) {
if (regex.length() == 0) {
Review Comment:
are we sure that `regex != null`?
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39651][table] REGEXP plan-time validation and hot-path log cleanup [flink]
Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #28292:
URL: https://github.com/apache/flink/pull/28292#discussion_r3340117635
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/SqlFunctionUtils.java:
##########
@@ -1015,14 +1015,19 @@ public static Integer hashCode(String str) {
return Math.abs(str.hashCode());
}
+ /**
+ * Returns whether {@code s} contains a match for the regular expression {@code regex}. Literal
+ * regexes are validated at planning time by the input type strategy.
+ */
public static Boolean regExp(String s, String regex) {
Review Comment:
any reason we have `Boolean` instead of `boolean`?
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39651][table] REGEXP plan-time validation and hot-path log cleanup [flink]
Posted by "raminqaf (via GitHub)" <gi...@apache.org>.
raminqaf commented on code in PR #28292:
URL: https://github.com/apache/flink/pull/28292#discussion_r3340412711
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/SqlFunctionUtils.java:
##########
@@ -1015,14 +1015,19 @@ public static Integer hashCode(String str) {
return Math.abs(str.hashCode());
}
+ /**
+ * Returns whether {@code s} contains a match for the regular expression {@code regex}. Literal
+ * regexes are validated at planning time by the input type strategy.
+ */
public static Boolean regExp(String s, String regex) {
if (regex.length() == 0) {
return false;
}
try {
- return (REGEXP_PATTERN_CACHE.get(regex)).matcher(s).find(0);
- } catch (Exception e) {
- LOG.error("Exception when compile and match regex:" + regex + " on: " + s, e);
+ return REGEXP_PATTERN_CACHE.get(regex).matcher(s).find(0);
+ } catch (PatternSyntaxException e) {
+ // Literals are rejected at planning time; non-literal invalid regex
+ // returns false to preserve the prior runtime contract.
return false;
Review Comment:
This is indeed strange and also raised by @twalthr on my `REGEXP_EXTRACT`: https://github.com/apache/flink/pull/28140#discussion_r3224575033
We can maybe follow this up and do the changes at once, which would be a breaking change but IMO a more correct behavior
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39651][table] REGEXP plan-time validation and hot-path log cleanup [flink]
Posted by "raminqaf (via GitHub)" <gi...@apache.org>.
raminqaf commented on code in PR #28292:
URL: https://github.com/apache/flink/pull/28292#discussion_r3340438815
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/SqlFunctionUtils.java:
##########
@@ -1015,14 +1015,19 @@ public static Integer hashCode(String str) {
return Math.abs(str.hashCode());
}
+ /**
+ * Returns whether {@code s} contains a match for the regular expression {@code regex}. Literal
+ * regexes are validated at planning time by the input type strategy.
+ */
public static Boolean regExp(String s, String regex) {
if (regex.length() == 0) {
Review Comment:
Thanks! Applied
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/SqlFunctionUtils.java:
##########
@@ -1015,14 +1015,19 @@ public static Integer hashCode(String str) {
return Math.abs(str.hashCode());
}
+ /**
+ * Returns whether {@code s} contains a match for the regular expression {@code regex}. Literal
+ * regexes are validated at planning time by the input type strategy.
+ */
public static Boolean regExp(String s, String regex) {
Review Comment:
changed to `boolean`
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39651][table] REGEXP plan-time validation and hot-path log cleanup [flink]
Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #28292:
URL: https://github.com/apache/flink/pull/28292#discussion_r3340136801
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/SqlFunctionUtils.java:
##########
@@ -1015,14 +1015,19 @@ public static Integer hashCode(String str) {
return Math.abs(str.hashCode());
}
+ /**
+ * Returns whether {@code s} contains a match for the regular expression {@code regex}. Literal
+ * regexes are validated at planning time by the input type strategy.
+ */
public static Boolean regExp(String s, String regex) {
if (regex.length() == 0) {
Review Comment:
same for `s`
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39651][table] REGEXP plan-time validation and hot-path log cleanup [flink]
Posted by "fhueske (via GitHub)" <gi...@apache.org>.
fhueske commented on code in PR #28292:
URL: https://github.com/apache/flink/pull/28292#discussion_r3340273562
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/SqlFunctionUtils.java:
##########
@@ -1015,14 +1015,19 @@ public static Integer hashCode(String str) {
return Math.abs(str.hashCode());
}
+ /**
+ * Returns whether {@code s} contains a match for the regular expression {@code regex}. Literal
+ * regexes are validated at planning time by the input type strategy.
+ */
public static Boolean regExp(String s, String regex) {
if (regex.length() == 0) {
return false;
}
try {
- return (REGEXP_PATTERN_CACHE.get(regex)).matcher(s).find(0);
- } catch (Exception e) {
- LOG.error("Exception when compile and match regex:" + regex + " on: " + s, e);
+ return REGEXP_PATTERN_CACHE.get(regex).matcher(s).find(0);
+ } catch (PatternSyntaxException e) {
+ // Literals are rejected at planning time; non-literal invalid regex
+ // returns false to preserve the prior runtime contract.
return false;
Review Comment:
AFAIK, most engines terminate a statement if they encounter an invalid regex pattern.
However, since the fix "just" removes the logging we are not changing the current behavior.
So this change is OK, IMO.
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/SqlFunctionUtils.java:
##########
@@ -1015,14 +1015,19 @@ public static Integer hashCode(String str) {
return Math.abs(str.hashCode());
}
+ /**
+ * Returns whether {@code s} contains a match for the regular expression {@code regex}. Literal
+ * regexes are validated at planning time by the input type strategy.
+ */
public static Boolean regExp(String s, String regex) {
if (regex.length() == 0) {
Review Comment:
The method call is wrapped in `GenerateUtils.generateCallIfArgsNotNull()`.
So the input args should not be null.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39651][table] REGEXP plan-time validation and hot-path log cleanup [flink]
Posted by "fhueske (via GitHub)" <gi...@apache.org>.
fhueske merged PR #28292:
URL: https://github.com/apache/flink/pull/28292
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39651][table] REGEXP plan-time validation and hot-path log cleanup [flink]
Posted by "raminqaf (via GitHub)" <gi...@apache.org>.
raminqaf commented on code in PR #28292:
URL: https://github.com/apache/flink/pull/28292#discussion_r3340440991
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/strategies/RegexpInputTypeStrategy.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.types.inference.strategies;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.table.functions.BuiltInFunctionDefinitions;
+import org.apache.flink.table.functions.FunctionDefinition;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.inference.ArgumentCount;
+import org.apache.flink.table.types.inference.ArgumentTypeStrategy;
+import org.apache.flink.table.types.inference.CallContext;
+import org.apache.flink.table.types.inference.ConstantArgumentCount;
+import org.apache.flink.table.types.inference.InputTypeStrategy;
+import org.apache.flink.table.types.inference.Signature;
+import org.apache.flink.table.types.inference.Signature.Argument;
+import org.apache.flink.table.types.logical.LogicalTypeFamily;
+
+import java.util.List;
+import java.util.Optional;
+
+import static org.apache.flink.table.types.inference.InputTypeStrategies.logical;
+
+/**
+ * Input type strategy for {@link BuiltInFunctionDefinitions#REGEXP}. Validates literal regex
+ * patterns at planning time.
+ */
+@Internal
+public class RegexpInputTypeStrategy implements InputTypeStrategy {
+
+ private static final int ARG_STR = 0;
+ private static final int ARG_REGEX = 1;
+
+ private static final ArgumentTypeStrategy STRING_ARG =
+ logical(LogicalTypeFamily.CHARACTER_STRING);
+
+ @Override
+ public ArgumentCount getArgumentCount() {
+ return ConstantArgumentCount.of(2);
+ }
+
+ @Override
+ public Optional<List<DataType>> inferInputTypes(
+ final CallContext callContext, final boolean throwOnFailure) {
+ if (STRING_ARG.inferArgumentType(callContext, ARG_STR, throwOnFailure).isEmpty()) {
+ return Optional.empty();
+ }
+ if (STRING_ARG.inferArgumentType(callContext, ARG_REGEX, throwOnFailure).isEmpty()) {
+ return Optional.empty();
+ }
+
+ final Optional<List<DataType>> patternError =
+ StrategyUtils.validateLiteralPattern(callContext, ARG_REGEX, throwOnFailure);
+ if (patternError.isPresent()) {
+ return patternError;
+ }
+
+ return Optional.of(callContext.getArgumentDataTypes());
+ }
+
+ @Override
+ public List<Signature> getExpectedSignatures(FunctionDefinition definition) {
Review Comment:
Addressed!
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39651][table] REGEXP plan-time validation and hot-path log cleanup [flink]
Posted by "gustavodemorais (via GitHub)" <gi...@apache.org>.
gustavodemorais commented on code in PR #28292:
URL: https://github.com/apache/flink/pull/28292#discussion_r3340166950
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/strategies/RegexpInputTypeStrategy.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.types.inference.strategies;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.table.functions.BuiltInFunctionDefinitions;
+import org.apache.flink.table.functions.FunctionDefinition;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.inference.ArgumentCount;
+import org.apache.flink.table.types.inference.ArgumentTypeStrategy;
+import org.apache.flink.table.types.inference.CallContext;
+import org.apache.flink.table.types.inference.ConstantArgumentCount;
+import org.apache.flink.table.types.inference.InputTypeStrategy;
+import org.apache.flink.table.types.inference.Signature;
+import org.apache.flink.table.types.inference.Signature.Argument;
+import org.apache.flink.table.types.logical.LogicalTypeFamily;
+
+import java.util.List;
+import java.util.Optional;
+
+import static org.apache.flink.table.types.inference.InputTypeStrategies.logical;
+
+/**
+ * Input type strategy for {@link BuiltInFunctionDefinitions#REGEXP}. Validates literal regex
+ * patterns at planning time.
+ */
+@Internal
+public class RegexpInputTypeStrategy implements InputTypeStrategy {
+
+ private static final int ARG_STR = 0;
+ private static final int ARG_REGEX = 1;
+
+ private static final ArgumentTypeStrategy STRING_ARG =
+ logical(LogicalTypeFamily.CHARACTER_STRING);
+
+ @Override
+ public ArgumentCount getArgumentCount() {
+ return ConstantArgumentCount.of(2);
+ }
+
+ @Override
+ public Optional<List<DataType>> inferInputTypes(
+ final CallContext callContext, final boolean throwOnFailure) {
+ if (STRING_ARG.inferArgumentType(callContext, ARG_STR, throwOnFailure).isEmpty()) {
+ return Optional.empty();
+ }
+ if (STRING_ARG.inferArgumentType(callContext, ARG_REGEX, throwOnFailure).isEmpty()) {
+ return Optional.empty();
+ }
+
+ final Optional<List<DataType>> patternError =
+ StrategyUtils.validateLiteralPattern(callContext, ARG_REGEX, throwOnFailure);
+ if (patternError.isPresent()) {
+ return patternError;
+ }
+
+ return Optional.of(callContext.getArgumentDataTypes());
+ }
+
+ @Override
+ public List<Signature> getExpectedSignatures(FunctionDefinition definition) {
Review Comment:
```suggestion
public List<Signature> getExpectedSignatures(final FunctionDefinition definition) {
```
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39651][table] REGEXP plan-time validation and hot-path log cleanup [flink]
Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #28292:
URL: https://github.com/apache/flink/pull/28292#discussion_r3340112669
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/SqlFunctionUtils.java:
##########
@@ -1015,14 +1015,19 @@ public static Integer hashCode(String str) {
return Math.abs(str.hashCode());
}
+ /**
+ * Returns whether {@code s} contains a match for the regular expression {@code regex}. Literal
+ * regexes are validated at planning time by the input type strategy.
+ */
public static Boolean regExp(String s, String regex) {
if (regex.length() == 0) {
Review Comment:
why not `isEmpty()`
`length` also does some calculations
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org