rubenada commented on code in PR #3420:
URL: https://github.com/apache/calcite/pull/3420#discussion_r1332613041
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -280,7 +280,11 @@ private static SqlCall transformConvert(SqlValidator
validator, SqlCall call) {
public static final SqlFunction LPAD =
SqlBasicFunction.create(
"LPAD",
- ReturnTypes.ARG0_NULLABLE_VARYING,
+ ReturnTypes.ARG0.andThen((binding, operandType) -> {
Review Comment:
To avoid code duplication, I'd suggest to extract the common pieces into an
aux method, e.g.:
```
/** The "LPAD(original_value, return_length[, pattern])" function. */
@LibraryOperator(libraries = {BIG_QUERY, ORACLE})
public static final SqlFunction LPAD =
SqlBasicFunction.create(
"LPAD",
ReturnTypes.ARG0.andThen(SqlLibraryOperators::deriveTypePad),
OperandTypes.STRING_NUMERIC_OPTIONAL_STRING,
SqlFunctionCategory.STRING);
/** The "RPAD(original_value, return_length[, pattern])" function. */
@LibraryOperator(libraries = {BIG_QUERY, ORACLE})
public static final SqlFunction RPAD =
SqlBasicFunction.create(
"RPAD",
ReturnTypes.ARG0.andThen(SqlLibraryOperators::deriveTypePad),
OperandTypes.STRING_NUMERIC_OPTIONAL_STRING,
SqlFunctionCategory.STRING);
private static RelDataType deriveTypePad(SqlOperatorBinding binding,
RelDataType type) {
SqlTypeName result = SqlTypeUtil.isBinary(type) ? SqlTypeName.VARBINARY
: SqlTypeName.VARCHAR;
return binding.getTypeFactory().createSqlType(result);
}
```
--
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]