normanj-bitquill commented on code in PR #3942:
URL: https://github.com/apache/calcite/pull/3942#discussion_r1747781019
##########
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 agree with you in theory, but I don't know how to do this in practice.
When I make the change so that the NULL type is returned if any argument is of
the NULL type, then the tests fail. They fail with this error occurring when
trying to convert the result.
```
java.lang.NoSuchMethodException: java.lang.Void.valueOf(void)
```
It looks like it is trying to the result to a Void type in Java. It never
went to an implementation of the `BITAND()` function. I also tried use a return
type of `java.lang.Long` for the relevant implementation of the `BITAND()`
function. This gives the a similar error but for the Long type error:
```
java.lang.NoSuchMethodException: java.lang.Long.voidValue()
```
Another way to look at this is that `BITAND(1, NULL)` should return a `NULL`
value of the type of the first argument. I am treating `BITAND(1, NULL)` as the
same as `BITAND(NULL, 1)`.
--
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]