Skip to content

ArithmeticValue always reports a nullable result type, even when both operands are not nullable #4622

Description

@g31pranjal

Noticed while reviewing #4617.

The problem

ArithmeticValue.getResultType() derives only the type code from the physical operator and takes the default nullability:

// ArithmeticValue.java
@Override
public Type getResultType() {
    return Type.primitiveType(operator.getResultTypeCode());
}

and the single-argument overload is nullable:

// Type.java
static Type primitiveType(@Nonnull final TypeCode typeCode) {
    return primitiveType(typeCode, true);
}

So a + b is typed nullable even when a and b are both not-nullable. Arithmetic on not-null operands cannot produce null, so this loses information for every arithmetic expression in the system.

Where it bites

In LogicalOperator.generateCorrelatedFieldAccess, the SQL AT ordinal is built as explodeOrdinal + 1, where the ordinal is a field of the explode result typed Type.primitiveType(INT, false) and the literal comes from LiteralValue.ofScalar(1), which is Type.fromObject(1) = Type.primitiveType(INT, false). Both operands are not-nullable, yet the sum is nullable, while the column is declared with DataType.Primitives.INTEGER.type(), i.e. IntegerType.notNullable(). The declared SQL type and the underlying value type therefore disagree.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingplannerRelated to the query planner

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions