Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2284,7 +2284,7 @@ private static RelDataType deriveTypeMapFromEntries(SqlOperatorBinding opBinding
@LibraryOperator(libraries = {BIG_QUERY, ORACLE, POSTGRESQL})
public static final SqlFunction CHR =
SqlBasicFunction.create("CHR",
ReturnTypes.CHAR,
ReturnTypes.CHAR_NULLABLE_IF_ARGS_NULLABLE,
OperandTypes.INTEGER,
SqlFunctionCategory.STRING);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,13 @@ public static SqlCall stripSeparator(SqlCall call) {
public static final SqlReturnTypeInference CHAR_FORCE_NULLABLE =
CHAR.andThen(SqlTypeTransforms.FORCE_NULLABLE);

/**
* Type-inference strategy whereby the result type of a call is
* CHAR(1), nullable if any argument is nullable.
*/
public static final SqlReturnTypeInference CHAR_NULLABLE_IF_ARGS_NULLABLE =
CHAR.andThen(SqlTypeTransforms.TO_NULLABLE);

/**
* Type-inference strategy whereby the result type of a call is a TINYINT.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2213,6 +2213,9 @@ void testCastToBoolean(CastType castType, SqlOperatorFixture f) {
f.checkScalar("chr(48)", "0", "CHAR(1) NOT NULL");
f.checkScalar("chr(0)", String.valueOf('\u0000'), "CHAR(1) NOT NULL");
f.checkNull("chr(null)");
// Test case for [CALCITE-6707] Type inference for CHR function is wrong
// https://issues.apache.org/jira/browse/CALCITE-6707
f.checkType("chr(CAST(null AS INTEGER))", "CHAR(1)");
};
final List<SqlLibrary> libraries =
list(SqlLibrary.BIG_QUERY, SqlLibrary.ORACLE, SqlLibrary.POSTGRESQL);
Expand Down