Skip to content

fix!: apply ReadRel projection during schema inference - #266

Open
alexandrefimov wants to merge 1 commit into
substrait-io:mainfrom
alexandrefimov:fix/read-projection-schema
Open

fix!: apply ReadRel projection during schema inference#266
alexandrefimov wants to merge 1 commit into
substrait-io:mainfrom
alexandrefimov:fix/read-projection-schema

Conversation

@alexandrefimov

Copy link
Copy Markdown

infer_rel_schema currently returns the full base_schema for a masked read. A mask selecting one field can therefore report all input fields, and emit mappings are evaluated against the wrong columns.

Apply the read projection before emit, following the Read Operator in spec v0.99.0. Recursively project struct fields, list elements, and map values while preserving their nullability and container types. Keep explicit RelRoot.names and the original input schema unchanged. For projected reads, leave correlations inside filter and best_effort_filter offset-based: Read Filtering explicitly places those predicates before projection.

Mask unwrapping is a compatibility choice. The unwrapping section describes singleton unwrapping by default but leaves its serialization as TBD. This change follows Java's type projector: it preserves structs and containers at every level regardless of maintain_singular_struct. For example, selecting only the string from a nested struct<i64, string> keeps a nested struct<string>, even with the flag false. The validator instead requires the flag for a single-field read projection.

Struct fields also follow Java's mask order, including reordered and repeated selections. The same spec page still lists column reordering as an open question, so preserving mask order and duplicates remains a compatibility choice.

Closes #264

BREAKING CHANGE: ReadRel projection masks now change inferred output schemas and the indices seen by emit and parent relations. Invalid mask field indices and selector/type mismatches now raise errors instead of being ignored.

`infer_rel_schema` currently returns the full `base_schema` for a masked read. A mask selecting one field can therefore report all input fields, and emit mappings are evaluated against the wrong columns.

Apply the read projection before emit, following the [Read Operator in spec v0.99.0](https://github.com/substrait-io/substrait/blob/v0.99.0/site/docs/relations/logical_relations.md#read-operator). Recursively project struct fields, list elements, and map values while preserving their nullability and container types. Keep explicit `RelRoot.names` and the original input schema unchanged. For projected reads, leave correlations inside `filter` and `best_effort_filter` offset-based: [Read Filtering](https://github.com/substrait-io/substrait/blob/v0.99.0/site/docs/relations/logical_relations.md#read-filtering) explicitly places those predicates before projection.

Mask unwrapping is a compatibility choice. The [unwrapping section](https://github.com/substrait-io/substrait/blob/v0.99.0/site/docs/expressions/field_references.md#unwrapping-behavior) describes singleton unwrapping by default but leaves its serialization as TBD. This change follows Java's type projector: it preserves structs and containers at every level regardless of `maintain_singular_struct`. For example, selecting only the string from a nested `struct<i64, string>` keeps a nested `struct<string>`, even with the flag false. The validator instead requires the flag for a single-field read projection.

Struct fields also follow Java's mask order, including reordered and repeated selections. The same spec page still lists column reordering as an open question, so preserving mask order and duplicates remains a compatibility choice.

Closes substrait-io#264

BREAKING CHANGE: ReadRel projection masks now change inferred output schemas and the indices seen by emit and parent relations. Invalid mask field indices and selector/type mismatches now raise errors instead of being ignored.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

infer_rel_schema ignores ReadRel.projection

1 participant