Skip to content

Commit

Permalink
[FLINK-32466] Replace STRING with CHARACTER for functions that don't …
Browse files Browse the repository at this point in the history
…support binary strings

This closes apache#22892.
  • Loading branch information
twalthr committed Jul 10, 2023
1 parent 2a6e8ae commit 4cf2124
Showing 1 changed file with 66 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ public void lookupOperatorOverloads(
ReturnTypes.explicit(SqlTypeName.VARCHAR),
SqlTypeTransforms.TO_NULLABLE))
.operandTypeChecker(
OperandTypes.repeat(SqlOperandCountRanges.from(1), OperandTypes.STRING))
OperandTypes.repeat(
SqlOperandCountRanges.from(1), OperandTypes.CHARACTER))
.build();

/** Function for concat strings with a separator. */
Expand All @@ -240,7 +241,7 @@ public void lookupOperatorOverloads(
ReturnTypes.explicit(SqlTypeName.VARCHAR),
SqlTypeTransforms.TO_NULLABLE),
null,
OperandTypes.repeat(SqlOperandCountRanges.from(1), OperandTypes.STRING),
OperandTypes.repeat(SqlOperandCountRanges.from(1), OperandTypes.CHARACTER),
SqlFunctionCategory.STRING);

public static final SqlFunction LOG =
Expand Down Expand Up @@ -311,7 +312,7 @@ public void lookupOperatorOverloads(
InferTypes.RETURN_TYPE,
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.INTEGER),
OperandTypes.family(SqlTypeFamily.STRING)),
OperandTypes.family(SqlTypeFamily.CHARACTER)),
SqlFunctionCategory.NUMERIC);

public static final SqlFunction STR_TO_MAP =
Expand All @@ -321,11 +322,11 @@ public void lookupOperatorOverloads(
STR_MAP_NULLABLE,
null,
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.STRING),
OperandTypes.family(SqlTypeFamily.CHARACTER),
OperandTypes.family(
SqlTypeFamily.STRING,
SqlTypeFamily.STRING,
SqlTypeFamily.STRING)),
SqlTypeFamily.CHARACTER,
SqlTypeFamily.CHARACTER,
SqlTypeFamily.CHARACTER)),
SqlFunctionCategory.STRING);

public static final SqlFunction IS_DECIMAL =
Expand Down Expand Up @@ -391,7 +392,9 @@ public void lookupOperatorOverloads(
SqlTypeTransforms.TO_NULLABLE),
null,
OperandTypes.family(
SqlTypeFamily.STRING, SqlTypeFamily.INTEGER, SqlTypeFamily.STRING),
SqlTypeFamily.CHARACTER,
SqlTypeFamily.INTEGER,
SqlTypeFamily.CHARACTER),
SqlFunctionCategory.STRING);

public static final SqlFunction RPAD =
Expand All @@ -403,7 +406,9 @@ public void lookupOperatorOverloads(
SqlTypeTransforms.TO_NULLABLE),
null,
OperandTypes.family(
SqlTypeFamily.STRING, SqlTypeFamily.INTEGER, SqlTypeFamily.STRING),
SqlTypeFamily.CHARACTER,
SqlTypeFamily.INTEGER,
SqlTypeFamily.CHARACTER),
SqlFunctionCategory.STRING);

public static final SqlFunction REPEAT =
Expand All @@ -414,7 +419,7 @@ public void lookupOperatorOverloads(
ReturnTypes.explicit(SqlTypeName.VARCHAR),
SqlTypeTransforms.TO_NULLABLE),
null,
OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.INTEGER),
OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.INTEGER),
SqlFunctionCategory.STRING);

public static final SqlFunction REVERSE =
Expand All @@ -423,7 +428,7 @@ public void lookupOperatorOverloads(
SqlKind.OTHER_FUNCTION,
VARCHAR_FORCE_NULLABLE,
null,
OperandTypes.family(SqlTypeFamily.STRING),
OperandTypes.family(SqlTypeFamily.CHARACTER),
SqlFunctionCategory.STRING);

public static final SqlFunction REPLACE =
Expand All @@ -435,7 +440,9 @@ public void lookupOperatorOverloads(
SqlTypeTransforms.TO_NULLABLE),
null,
OperandTypes.family(
SqlTypeFamily.STRING, SqlTypeFamily.STRING, SqlTypeFamily.STRING),
SqlTypeFamily.CHARACTER,
SqlTypeFamily.CHARACTER,
SqlTypeFamily.CHARACTER),
SqlFunctionCategory.STRING);

public static final SqlFunction SPLIT_INDEX =
Expand All @@ -446,12 +453,12 @@ public void lookupOperatorOverloads(
null,
OperandTypes.or(
OperandTypes.family(
SqlTypeFamily.STRING,
SqlTypeFamily.CHARACTER,
SqlTypeFamily.INTEGER,
SqlTypeFamily.INTEGER),
OperandTypes.family(
SqlTypeFamily.STRING,
SqlTypeFamily.STRING,
SqlTypeFamily.CHARACTER,
SqlTypeFamily.CHARACTER,
SqlTypeFamily.INTEGER)),
SqlFunctionCategory.STRING);

Expand All @@ -464,7 +471,9 @@ public void lookupOperatorOverloads(
SqlTypeTransforms.TO_NULLABLE),
null,
OperandTypes.family(
SqlTypeFamily.STRING, SqlTypeFamily.STRING, SqlTypeFamily.STRING),
SqlTypeFamily.CHARACTER,
SqlTypeFamily.CHARACTER,
SqlTypeFamily.CHARACTER),
SqlFunctionCategory.STRING);

public static final SqlFunction REGEXP_EXTRACT =
Expand All @@ -473,7 +482,12 @@ public void lookupOperatorOverloads(
SqlKind.OTHER_FUNCTION,
VARCHAR_FORCE_NULLABLE,
null,
OperandTypes.or(OperandTypes.STRING_STRING_INTEGER, OperandTypes.STRING_STRING),
OperandTypes.or(
OperandTypes.family(
SqlTypeFamily.CHARACTER,
SqlTypeFamily.CHARACTER,
SqlTypeFamily.INTEGER),
OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.CHARACTER)),
SqlFunctionCategory.STRING);

public static final SqlFunction HASH_CODE =
Expand All @@ -485,7 +499,7 @@ public void lookupOperatorOverloads(
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.BOOLEAN),
OperandTypes.family(SqlTypeFamily.NUMERIC),
OperandTypes.family(SqlTypeFamily.STRING),
OperandTypes.family(SqlTypeFamily.CHARACTER),
OperandTypes.family(SqlTypeFamily.TIMESTAMP),
OperandTypes.family(SqlTypeFamily.TIME),
OperandTypes.family(SqlTypeFamily.DATE)),
Expand Down Expand Up @@ -578,8 +592,8 @@ public void lookupOperatorOverloads(
VARCHAR_FORCE_NULLABLE,
InferTypes.RETURN_TYPE,
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.TIMESTAMP, SqlTypeFamily.STRING),
OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.STRING)),
OperandTypes.family(SqlTypeFamily.TIMESTAMP, SqlTypeFamily.CHARACTER),
OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.CHARACTER)),
SqlFunctionCategory.TIMEDATE);

public static final SqlFunction REGEXP =
Expand All @@ -588,7 +602,7 @@ public void lookupOperatorOverloads(
SqlKind.OTHER_FUNCTION,
ReturnTypes.BOOLEAN_NULLABLE,
null,
OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.STRING),
OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.CHARACTER),
SqlFunctionCategory.STRING);

public static final SqlFunction PARSE_URL =
Expand All @@ -598,11 +612,11 @@ public void lookupOperatorOverloads(
VARCHAR_FORCE_NULLABLE,
null,
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.STRING),
OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.CHARACTER),
OperandTypes.family(
SqlTypeFamily.STRING,
SqlTypeFamily.STRING,
SqlTypeFamily.STRING)),
SqlTypeFamily.CHARACTER,
SqlTypeFamily.CHARACTER,
SqlTypeFamily.CHARACTER)),
SqlFunctionCategory.STRING);

public static final SqlFunction PRINT =
Expand All @@ -611,7 +625,7 @@ public void lookupOperatorOverloads(
SqlKind.OTHER_FUNCTION,
ReturnTypes.ARG1_NULLABLE,
null,
OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.ANY),
OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.ANY),
SqlFunctionCategory.STRING);

// Flink timestamp functions
Expand All @@ -632,9 +646,9 @@ public SqlSyntax getSyntax() {
.operandTypeChecker(
OperandTypes.or(
OperandTypes.NILADIC,
OperandTypes.family(SqlTypeFamily.STRING),
OperandTypes.family(SqlTypeFamily.CHARACTER),
OperandTypes.family(
SqlTypeFamily.STRING, SqlTypeFamily.STRING)))
SqlTypeFamily.CHARACTER, SqlTypeFamily.CHARACTER)))
.notDeterministic()
.monotonicity(
call -> {
Expand All @@ -654,7 +668,7 @@ public SqlSyntax getSyntax() {
null,
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.INTEGER),
OperandTypes.family(SqlTypeFamily.INTEGER, SqlTypeFamily.STRING)),
OperandTypes.family(SqlTypeFamily.INTEGER, SqlTypeFamily.CHARACTER)),
SqlFunctionCategory.TIMEDATE);

public static final SqlFunction IF =
Expand All @@ -676,8 +690,8 @@ public SqlSyntax getSyntax() {
// used for a more explicit exception message
OperandTypes.family(
SqlTypeFamily.BOOLEAN,
SqlTypeFamily.STRING,
SqlTypeFamily.STRING),
SqlTypeFamily.CHARACTER,
SqlTypeFamily.CHARACTER),
OperandTypes.family(
SqlTypeFamily.BOOLEAN,
SqlTypeFamily.BOOLEAN,
Expand Down Expand Up @@ -764,7 +778,7 @@ public SqlSyntax getSyntax() {
SqlKind.OTHER_FUNCTION,
ARG0_VARCHAR_FORCE_NULLABLE,
null,
OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.INTEGER),
OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.INTEGER),
SqlFunctionCategory.STRING);

public static final SqlFunction RIGHT =
Expand All @@ -773,7 +787,7 @@ public SqlSyntax getSyntax() {
SqlKind.OTHER_FUNCTION,
ARG0_VARCHAR_FORCE_NULLABLE,
null,
OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.INTEGER),
OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.INTEGER),
SqlFunctionCategory.STRING);

// TODO: the return type of TO_TIMESTAMP should be TIMESTAMP(9),
Expand Down Expand Up @@ -812,8 +826,8 @@ public SqlSyntax getSyntax() {
SqlTypeTransforms.FORCE_NULLABLE),
null,
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.STRING),
OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.STRING)),
OperandTypes.family(SqlTypeFamily.CHARACTER),
OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.CHARACTER)),
SqlFunctionCategory.TIMEDATE);

public static final SqlFunction CONVERT_TZ =
Expand All @@ -823,7 +837,9 @@ public SqlSyntax getSyntax() {
VARCHAR_FORCE_NULLABLE,
null,
OperandTypes.family(
SqlTypeFamily.STRING, SqlTypeFamily.STRING, SqlTypeFamily.STRING),
SqlTypeFamily.CHARACTER,
SqlTypeFamily.CHARACTER,
SqlTypeFamily.CHARACTER),
SqlFunctionCategory.TIMEDATE);

public static final SqlFunction LOCATE =
Expand All @@ -833,10 +849,10 @@ public SqlSyntax getSyntax() {
ReturnTypes.INTEGER_NULLABLE,
null,
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.STRING),
OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.CHARACTER),
OperandTypes.family(
SqlTypeFamily.STRING,
SqlTypeFamily.STRING,
SqlTypeFamily.CHARACTER,
SqlTypeFamily.CHARACTER,
SqlTypeFamily.INTEGER)),
SqlFunctionCategory.NUMERIC);

Expand All @@ -857,7 +873,7 @@ public SqlSyntax getSyntax() {
ReturnTypes.explicit(SqlTypeName.BINARY),
SqlTypeTransforms.FORCE_NULLABLE),
null,
OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.STRING),
OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.CHARACTER),
SqlFunctionCategory.STRING);

public static final SqlFunction DECODE =
Expand All @@ -866,7 +882,7 @@ public SqlSyntax getSyntax() {
SqlKind.OTHER_FUNCTION,
VARCHAR_FORCE_NULLABLE,
null,
OperandTypes.family(SqlTypeFamily.BINARY, SqlTypeFamily.STRING),
OperandTypes.family(SqlTypeFamily.BINARY, SqlTypeFamily.CHARACTER),
SqlFunctionCategory.STRING);

public static final SqlFunction INSTR =
Expand All @@ -876,14 +892,14 @@ public SqlSyntax getSyntax() {
ReturnTypes.INTEGER_NULLABLE,
null,
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.STRING),
OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.CHARACTER),
OperandTypes.family(
SqlTypeFamily.STRING,
SqlTypeFamily.STRING,
SqlTypeFamily.CHARACTER,
SqlTypeFamily.CHARACTER,
SqlTypeFamily.INTEGER),
OperandTypes.family(
SqlTypeFamily.STRING,
SqlTypeFamily.STRING,
SqlTypeFamily.CHARACTER,
SqlTypeFamily.CHARACTER,
SqlTypeFamily.INTEGER,
SqlTypeFamily.INTEGER)),
SqlFunctionCategory.NUMERIC);
Expand All @@ -898,8 +914,8 @@ public SqlSyntax getSyntax() {
SqlTypeTransforms.TO_VARYING),
null,
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.STRING),
OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.STRING)),
OperandTypes.family(SqlTypeFamily.CHARACTER),
OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.CHARACTER)),
SqlFunctionCategory.STRING);

public static final SqlFunction RTRIM =
Expand All @@ -912,8 +928,8 @@ public SqlSyntax getSyntax() {
SqlTypeTransforms.TO_VARYING),
null,
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.STRING),
OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.STRING)),
OperandTypes.family(SqlTypeFamily.CHARACTER),
OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.CHARACTER)),
SqlFunctionCategory.STRING);

public static final SqlFunction TRY_CAST = new SqlTryCastFunction();
Expand Down

0 comments on commit 4cf2124

Please sign in to comment.