Problem
SubstraitRelVisitor.visit(Values) currently uses the LogicalValues row schema
only to override literal nullability. The remaining Substrait literal type is
derived from the tuple's RexLiteral type.
Calcite can represent a LogicalValues field with a wider row type than its
literal. For example, an INTEGER row field may contain a TINYINT literal.
Converting that relation creates an I32 virtual-table schema and an I8 row
field. VirtualTableScan then rejects the mismatch:
Row field type (I8{nullable=false}) does not match schema field type (I32{nullable=false})
This is the same class of schema/literal mismatch addressed for nullability by
#683 and #684, but it also affects type width and other schema type attributes.
Minimal reproducer
RelDataType rowType =
typeFactory.builder().add("col1", SqlTypeName.INTEGER).build();
RexLiteral literal =
builder
.getRexBuilder()
.makeExactLiteral(
BigDecimal.ONE, typeFactory.createSqlType(SqlTypeName.TINYINT));
LogicalValues values =
LogicalValues.create(
builder.getCluster(), rowType, ImmutableList.of(ImmutableList.of(literal)));
SubstraitRelVisitor.convert(values, converterProvider);
Expected behavior
The virtual-table row should use the complete type of the corresponding
LogicalValues schema field. The example should produce an I32 literal with
value 1, matching the I32 schema.
Schema validation should remain strict; this change should normalize compatible
literals to the schema type rather than relaxing VirtualTableScan validation.
Proposed direction
Pass the schema field's RelDataType to LiteralConverter when converting
LogicalValues tuples. Use that type for width, precision, scale and
nullability while retaining the literal's value.
Problem
SubstraitRelVisitor.visit(Values)currently uses theLogicalValuesrow schemaonly to override literal nullability. The remaining Substrait literal type is
derived from the tuple's
RexLiteraltype.Calcite can represent a
LogicalValuesfield with a wider row type than itsliteral. For example, an
INTEGERrow field may contain aTINYINTliteral.Converting that relation creates an
I32virtual-table schema and anI8rowfield.
VirtualTableScanthen rejects the mismatch:This is the same class of schema/literal mismatch addressed for nullability by
#683 and #684, but it also affects type width and other schema type attributes.
Minimal reproducer
Expected behavior
The virtual-table row should use the complete type of the corresponding
LogicalValuesschema field. The example should produce anI32literal withvalue
1, matching theI32schema.Schema validation should remain strict; this change should normalize compatible
literals to the schema type rather than relaxing
VirtualTableScanvalidation.Proposed direction
Pass the schema field's
RelDataTypetoLiteralConverterwhen convertingLogicalValuestuples. Use that type for width, precision, scale andnullability while retaining the literal's value.