Skip to content

isthmus: ITEM on a ROW passes Calcite's 1-based index through as a 0-based struct field #1385

Description

@nielspardon

FieldSelectionConverter passes the integer index of a Calcite ITEM(row, n) call straight through as a 0-based struct_field offset. Calcite's ROW ITEM is 1-based (SqlItemOperator.inferReturnType reads getFieldList().get(index - 1)), so the conversion selects the next field over, and an index equal to the field count throws.

// $0 : ROW(a INTEGER, b VARCHAR(10))
rexBuilder.makeCall(SqlStdOperatorTable.ITEM, $0, 1)  // Calcite type INTEGER (field a)
// -> FieldReference{[StructField 1, StructField 0]}, type varchar<10>  (field b)
rexBuilder.makeCall(SqlStdOperatorTable.ITEM, $0, 2)  // Calcite type VARCHAR(10) (field b)
// -> IndexOutOfBoundsException: Index 2 out of bounds for length 2

Measured on main at 559c80e. SQL r[1] is not affected, because StandardConvertletTable.convertItem lowers it to a RexFieldAccess; only calls built through RexBuilder/RelBuilder reach this branch. The ARRAY branch of the same method has the same base error, which #1261 fixes; the fix here is to subtract 1 from the ROW index the same way.

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