normanj-bitquill commented on code in PR #3942:
URL: https://github.com/apache/calcite/pull/3942#discussion_r1745882348
##########
core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java:
##########
@@ -613,6 +613,59 @@ public static SqlCall stripSeparator(SqlCall call) {
public static final SqlReturnTypeInference ARG0_EXCEPT_INTEGER_NULLABLE =
ARG0_EXCEPT_INTEGER.andThen(SqlTypeTransforms.TO_NULLABLE);
+ /**
+ * Returns the type of the first non NULL argument or INTEGER if all
arguments
+ * are NULL.
+ */
+ public static final SqlReturnTypeInference
LARGEST_INT_OR_FIRST_NON_NULL_DEFAULT_INTEGER =
+ opBinding -> {
+ final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
+ RelDataType integerReturnType = null;
+ boolean allArgsInteger = true;
+ for (RelDataType opType : opBinding.collectOperandTypes()) {
+ if (SqlTypeName.INT_TYPES.contains(opType.getSqlTypeName())) {
+ if (integerReturnType == null) {
+ integerReturnType = opType;
+ } else if (isIntegerTypeLarger(integerReturnType, opType)) {
+ integerReturnType = opType;
+ }
+ } else {
+ allArgsInteger = false;
+ break;
+ }
+ }
+ if (integerReturnType != null && allArgsInteger) {
+ return typeFactory.createTypeWithNullability(integerReturnType,
true);
+ }
+ for (RelDataType opType : opBinding.collectOperandTypes()) {
+ if (!opType.isNullable()) {
+ return typeFactory.createTypeWithNullability(opType, true);
+ }
+ }
+ return typeFactory.createTypeWithNullability(
Review Comment:
I have reworked the logic here.
If all arguments are of the NULL type, then the return type is INTEGER
nullable.
If all arguments are integer types, then the return type is the largest type
found. It is nullable if at least one argument is nullable.
As a fallback, the first argument that is not of the NULL type is the return
type. It is nullable if at least one argument is nullable.
--
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]