Skip to content

Commit

Permalink
[hotfix][table] REGEXP_EXTRACT return type should always be nullable
Browse files Browse the repository at this point in the history
This closes apache#17242.
  • Loading branch information
slinkydeveloper authored and twalthr committed Sep 13, 2021
1 parent 8d94540 commit 6899a44
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ ANY, and(logical(LogicalTypeRoot.BOOLEAN), LITERAL)
logical(LogicalTypeFamily.CHARACTER_STRING),
logical(LogicalTypeFamily.CHARACTER_STRING),
logical(LogicalTypeRoot.INTEGER))))
.outputTypeStrategy(nullableIfArgs(explicit(DataTypes.STRING())))
.outputTypeStrategy(explicit(DataTypes.STRING().nullable()))
.build();

public static final BuiltInFunctionDefinition FROM_BASE64 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ public void lookupOperatorOverloads(
SqlKind.OTHER_FUNCTION,
ReturnTypes.cascade(
ReturnTypes.explicit(SqlTypeName.VARCHAR),
SqlTypeTransforms.TO_NULLABLE),
SqlTypeTransforms.FORCE_NULLABLE),
null,
OperandTypes.or(OperandTypes.STRING_STRING_INTEGER, OperandTypes.STRING_STRING),
SqlFunctionCategory.STRING);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.planner.functions;

import org.apache.flink.table.api.DataTypes;
import org.apache.flink.table.functions.BuiltInFunctionDefinitions;

import org.junit.runners.Parameterized;

import java.util.Arrays;
import java.util.List;

import static org.apache.flink.table.api.Expressions.$;
import static org.apache.flink.table.api.Expressions.call;

/** Test String functions correct behaviour. */
public class StringFunctionsITCase extends BuiltInFunctionTestBase {

@Parameterized.Parameters(name = "{index}: {0}")
public static List<TestSpec> testData() {
return Arrays.asList(
TestSpec.forFunction(BuiltInFunctionDefinitions.REGEXP_EXTRACT, "Check return type")
.onFieldsWithData("22", "ABC")
.testResult(
call("regexpExtract", $("f0"), "[A-Z]+"),
"REGEXP_EXTRACT(f0,'[A-Z]+')",
null,
DataTypes.STRING().nullable())
.testResult(
call("regexpExtract", $("f1"), "[A-Z]+"),
"REGEXP_EXTRACT(f1, '[A-Z]+')",
"ABC",
DataTypes.STRING().nullable()));
}
}

0 comments on commit 6899a44

Please sign in to comment.