Skip to content

feat(iceberg): thread per-file sort order into FileScanTask - #3128

Open
anuragmantri wants to merge 3 commits into
apache:mainfrom
anuragmantri:feat/sort-order-file-scan-task
Open

feat(iceberg): thread per-file sort order into FileScanTask#3128
anuragmantri wants to merge 3 commits into
apache:mainfrom
anuragmantri:feat/sort-order-file-scan-task

Conversation

@anuragmantri

Copy link
Copy Markdown

Which issue does this PR close?

What changes are included in this PR?

Resolves each manifest entry's DataFile.sort_order_id against the table's known sort orders and carries the result on a new FileScanTask.sort_order field. This follows the same PlanContext -> ManifestFileContext -> ManifestEntryContext plumbing already used for unified_partition_type. None means no sort order could be established, either because the file has no recorded sort_order_id, or because the id doesn't resolve against the table's known sort orders.

This is groundwork for propagating sort-order awareness into the DataFusion integration (Part 2 of #3126), which needs per-file sort-order data to decide whether a scan's output can be safely reported as sorted.

Are these changes tested?

Yes, a unit test covers all three resolution outcomes:

  • a sort_order_id that resolves
  • a file with no sort_order_id at all, and
  • a sort_order_id that doesn't resolve against the table's sort orders.

The manifest-writing setup for this is factored into a new shared fixture helper alongside the existing setup_* variants.

AI Disclosure

I'm new to Rust and this codebase. I used Claude code (Opus 5) to assist me with the PR and the test coverage and I manually reviewed it. Please bear with me as I get familiar with Rust and the codebase.

@anuragmantri
anuragmantri force-pushed the feat/sort-order-file-scan-task branch from e285cc5 to 187999e Compare August 31, 2026 23:29
@anuragmantri

Copy link
Copy Markdown
Author

@mbutrovich - Since you have context on this work, could you please take a look? Thanks!

@anoopj anoopj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Code looks right to me. Just one comment about unsorted files.

Comment thread crates/iceberg/src/scan/task.rs Outdated
pub unified_partition_type: Option<Arc<StructType>>,

/// The sort order that this file's rows are sorted by, resolved from the data file's
/// `sort_order_id` against the table's known sort orders. `None` if the file has no

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note that Iceberg reserves 0 for unsorted. Per the spec:

Order id 0 is reserved for the unsorted order.

So a file with sort_order_id = 0 will resolve to unsorted order whereas a missing or unresolvable id gives None. So the datafusion consumer will need to check for both. e.g. something like sort_order.as_ref().is_some_and(|o| !o.is_unsorted())

May be a good idea to clarify this in the docs.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch. I changed it so that Some is returned only when the file has valid sort order (>0).

@anuragmantri

Copy link
Copy Markdown
Author

Thanks for the review @anoopj. I addressed your feedback.

@anoopj

anoopj commented Sep 2, 2026

Copy link
Copy Markdown
Member

@CTTY @blackmwk @laskoviymishka Could you please review?

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.

feat(iceberg): thread per-file sort order into FileScanTask

2 participants