Skip to content

feat: Propagate orderings through struct-producing projections#39

Merged
rkrishn7 merged 6 commits intobranch-51from
rohan/propagate-ordering-struct
Mar 27, 2026
Merged

feat: Propagate orderings through struct-producing projections#39
rkrishn7 merged 6 commits intobranch-51from
rohan/propagate-ordering-struct

Conversation

@rkrishn7
Copy link
Copy Markdown
Collaborator

When a projection wraps columns into a struct via named_struct (e.g., named_struct('ticker', ticker, ...) AS details), the optimizer loses track of the input column's ordering because ProjectionMapping maps the entire named_struct(...) expression to col("details"). Notably, it has no field-level decomposition, so it can't prove that get_field(details, "ticker") actually preserves the ordering of the input ticker column. This means ORDER BY details['ticker'] will require a SortExec, even when the input is already sorted by ticker.

This PR fixes this by adding ScalarUDFImpl::struct_field_mapping that struct-producing UDFs can implement to declare their field-to-input-arg relationships, which ProjectionMapping then uses to add field-level entries so EquivalenceProperties can propagate orderings through the struct boundary.

Copy link
Copy Markdown
Collaborator

@zhuqi-lucas zhuqi-lucas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Clean design and good test coverage.

One issue: is_multiple_of in named_struct.rs:190 is nightly-only (feature(unsigned_is_multiple_of)). This will fail on stable Rust. Should use literal_args.len() % 2 != 0 instead.

@rkrishn7
Copy link
Copy Markdown
Collaborator Author

LGTM! Clean design and good test coverage.

One issue: is_multiple_of in named_struct.rs:190 is nightly-only (feature(unsigned_is_multiple_of)). This will fail on stable Rust. Should use literal_args.len() % 2 != 0 instead.

Thanks @zhuqi-lucas

usize::is_multiple_of should be stable since 1.87.0 🤔 - https://doc.rust-lang.org/std/primitive.usize.html#method.is_multiple_of

clippy actually instructed me to use is_multiple_of

@rkrishn7 rkrishn7 merged commit a74352d into branch-51 Mar 27, 2026
58 checks passed
zhuqi-lucas added a commit that referenced this pull request Mar 30, 2026
…#39) (#42)

Co-authored-by: Rohan Krishnaswamy <47869999+rkrishn7@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants