AHeise commented on code in PR #28189: URL: https://github.com/apache/flink/pull/28189#discussion_r3257762365
########## flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/strategies/RegexpUtils.java: ########## @@ -0,0 +1,64 @@ +/* + * 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.types.DataType; +import org.apache.flink.table.types.inference.CallContext; + +import java.util.List; +import java.util.Optional; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +/** Shared helpers for input type strategies of the regex function family. */ +@Internal +public final class RegexpUtils { Review Comment: Check if there are other validation utils already. ########## flink-table/flink-table-common/src/main/java/org/apache/flink/table/functions/BuiltInFunctionDefinitions.java: ########## @@ -1678,15 +1678,11 @@ ANY, and(logical(LogicalTypeRoot.BOOLEAN), LITERAL) public static final BuiltInFunctionDefinition REGEXP_REPLACE = BuiltInFunctionDefinition.newBuilder() - .name("regexpReplace") - .sqlName("REGEXP_REPLACE") + .name("REGEXP_REPLACE") Review Comment: I don't understand these changes. Why are we changing the name here? ########## flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/expressions/converter/DirectConvertRule.java: ########## @@ -197,8 +197,6 @@ void initNonDynamicFunctions() { BuiltInFunctionDefinitions.REPEAT, FlinkSqlOperatorTable.REPEAT); definitionSqlOperatorHashMap.put( BuiltInFunctionDefinitions.REGEXP, FlinkSqlOperatorTable.REGEXP); - definitionSqlOperatorHashMap.put( Review Comment: Why do we need to remove it here? What about the REGEXP funciton above? ########## flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/inference/strategies/RegexpExtractInputTypeStrategyTest.java: ########## @@ -55,6 +55,6 @@ protected Stream<TestSpec> testData() { TestSpec.forStrategy("Invalid literal regex fails at plan time", REGEXP_EXTRACT) .calledWithArgumentTypes(DataTypes.STRING(), DataTypes.STRING()) .calledWithLiteralAt(1, "(") - .expectErrorMessage("Invalid regular expression for REGEXP_EXTRACT:")); Review Comment: Readd it to the error message. Just pass the name to the validation. ########## flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/SqlFunctionUtils.java: ########## @@ -422,21 +422,20 @@ public static String splitIndex(String str, int character, int index) { /** * Returns a string resulting from replacing all substrings that match the regular expression - * with replacement. + * with replacement. Literal regexes are validated at planning time by the input type strategy. */ public static String regexpReplace(String str, String regex, String replacement) { if (str == null || regex == null || replacement == null) { return null; } try { - return str.replaceAll(regex, Matcher.quoteReplacement(replacement)); - } catch (Exception e) { - LOG.error( - String.format( - "Exception in regexpReplace('%s', '%s', '%s')", - str, regex, replacement), - e); - // return null if exception in regex replace + return REGEXP_PATTERN_CACHE Review Comment: Why is this change needed? -- 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]
