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.
FieldSelectionConverterpasses the integer index of a CalciteITEM(row, n)call straight through as a 0-basedstruct_fieldoffset. Calcite's ROWITEMis 1-based (SqlItemOperator.inferReturnTypereadsgetFieldList().get(index - 1)), so the conversion selects the next field over, and an index equal to the field count throws.Measured on
mainat 559c80e. SQLr[1]is not affected, becauseStandardConvertletTable.convertItemlowers it to aRexFieldAccess; only calls built throughRexBuilder/RelBuilderreach 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.