Skip to content

isthmus: a SQL ROW column's NOT NULL fields become nullable when the column is nullable #1341

Description

@nielspardon

Converting SQL to Substrait, a nullable ROW column loses its fields' NOT NULL:

CREATE TABLE src (c ROW(a INT NOT NULL, b DOUBLE));
SELECT c FROM src;

The root's record type comes back as struct<struct?<i32?, fp64?>>, with a nullable. Measured on main at 4bb02974, through SubstraitCreateStatementParser.processCreateStatementsToCatalog and SqlToSubstrait.

The widening happens in Calcite before isthmus sees the type: SqlDataTypeSpec.deriveType ends in fixUpNullability, which calls createTypeWithNullability, the method that makes a record's fields nullable along with the record. SubstraitCreateStatementParser (line 300) and DdlSqlToRelConverter (line 157) both take the column type from there. This is the Calcite-to-Substrait counterpart of #1154, which #1317 fixed in the other direction.

Calcite does this on purpose: its comment on createTypeWithNullability says that under the SQL standard a nested field of a nullable row is always nullable. Substrait can express the narrower type, so the question is whether isthmus should rebuild the column type with enforceTypeWithNullability to keep what the DDL declared, or accept Calcite's SQL reading.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions