Skip to content

fix(reader): widen promoted page-index bounds to the field type - #3521

Open
rich7420 wants to merge 7 commits into
apache:mainfrom
rich7420:feat/page-index-widen-promoted-bounds
Open

rich7420 wants to merge 7 commits into
apache:mainfrom
rich7420:feat/page-index-widen-promoted-bounds

Conversation

@rich7420

@rich7420 rich7420 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Note

This PR was stacked on #3507, which has been merged. I merged main into this branch, so the diff now shows only this PR's changes. The commit list still shows the #3507 commits.

Which issue does this PR close?

What changes are included in this PR?

This implements the widening follow-up agreed in #3507. That PR prevents pruning based on incomparable page-index bounds, such as INT32 bounds read as a long field after an int -> long promotion. This PR widens supported bounds to the field type so inequality and IN predicates can prune these pages.

  • Signed INT32 bounds for a long field and FLOAT bounds for a double field are widened with Datum::promote_to, added in #3483.
  • UINT_32 bounds are stored as INT32 bit patterns ordered as unsigned values. The column descriptor’s sort order identifies unsigned bounds, which are zero-extended to long. If this produces min > max, as can happen with bounds written in signed order, both bounds are discarded.
  • If either FLOAT or DOUBLE bound is NaN, both bounds are discarded. Legacy writers may store NaN bounds for pages that also contain other values, as documented in the Parquet specification. Datum uses total_cmp for floating-point comparisons, so trusting these bounds can prune matching pages. Widening exposes promoted double fields to this risk too. #3502 added a related NaN guard for row-group inequality pruning.

Discarding bounds prevents pruning based on those bounds; null-count checks and other predicates still apply. Bounds that remain incomparable, such as INT32 bounds for a timestamp field, retain the conservative fallback from #3507.

Are these changes tested?

Yes. Evaluator tests in page_index_evaluator.rs use metadata from real Parquet files and assert exact row selections. The NaN cases substitute synthetic column indexes.

  • long field over INT32 pages: <, <=, >, >=, < with a literal above i32::MAX, > with i32::MAX, and two-value IN.
  • double field over FLOAT pages: <, <=, >, >=, and two-value IN.
  • long field over UINT_32 pages, including a value above i32::MAX and a page mixing 100 and 3_000_000_000: =, >, <, and IN.
  • FLOAT pages read as native float or promoted double, and DOUBLE pages read as native double: pages with a NaN minimum or maximum are kept for =, <, >, and two-value IN.
  • timestamp field over INT32 pages: the existing fallback test checks that every page is kept for <, <=, >, >=, =, and IN.

Helper tests also verify that signed-order UINT_32 bounds are discarded, correctly ordered bounds are widened, and both floating-point bounds are discarded if either is NaN while finite bounds are preserved.

After I merged main, mutation checks confirmed that sign-extending UINT_32 bounds, removing the min > max check, and removing the NaN check each cause at least one test to fail. cargo test -p iceberg --lib expr::visitors and cargo test -p iceberg --lib arrow passed, as did cargo fmt --all -- --check and cargo clippy -p iceberg --all-targets --all-features -- -D warnings.

AI Disclosure

Drafted with Claude Code and reviewed with Codex. Review focus: whether zero-extension and the signed-order check are correct for UINT_32 columns, and whether discarding both bounds when either is NaN is conservative across predicates.

…e predicate

Page-index bounds are built with the table field type but the file's
physical literal. When the two differ, e.g. a long field read against
INT32 pages written before an int -> long promotion, a double field
against FLOAT pages, or a UINT_32 column mapped to long, the bounds
never compare with the predicate literal. Inequality and IN predicates
treated that as "cannot match" and skipped pages holding matching rows.

Keep a page whenever its bound cannot be compared with the literal: the
inequality check now treats an incomparable bound as a possible match,
and IN uses all(lt) / all(gt) instead of !any(ge) / !any(le).
A page holding both 100 and 3_000_000_000 has a raw signed max below its
min, which pins the unsigned column order that a later bound widening has
to zero-extend rather than sign-extend.
Page bounds written before an int -> long or float -> double promotion
are now widened with Datum::promote_to, so inequality and IN predicates
can prune these pages instead of keeping them all. UINT_32 bounds are
INT32 bits in unsigned order, so they are zero-extended; if the result
has min > max the writer used signed order and the page is kept.
Legacy writers may store NaN page bounds for pages holding other values.
Datum compares floats with total_cmp, so such a bound, now also produced
by widening FLOAT bounds to double, could prune a matching page. Drop
both bounds of a FLOAT or DOUBLE page when either is NaN, so the page
might match.
comphead added a commit to comphead/iceberg-rust that referenced this pull request Oct 26, 2026
A file written before an int -> long, float -> double, or decimal
precision promotion keeps its old physical type, while the predicate is
bound to the table type. The row filter cast the literal down to the
file's Arrow type, so an out-of-range literal became null and dropped
every row, and a double literal was rounded to f32.

Cast a numeric column to the table type before comparing instead, as
RecordBatchTransformer does for the output. Other columns keep the
literal cast. Page-index pruning is left to apache#3507 and apache#3521.

Part of apache#3122.
comphead added a commit to comphead/iceberg-rust that referenced this pull request Oct 27, 2026
Predicates are bound to the table schema, but the row filter evaluated
them on batches in the file's physical types. For a file written before
an int -> long, float -> double, or decimal precision promotion,
try_cast_literal cast the literal down to the file type, so an
out-of-range literal became null and dropped every row, and a double
literal was rounded to f32.

Convert the filter columns to the table schema with a
RecordBatchTransformer, as the reader does for its output, and make
try_cast_literal fail instead of returning null. Page-index pruning is
left to apache#3507 and apache#3521.

Part of apache#3122.
@CTTY CTTY mentioned this pull request Nov 17, 2026
3 tasks
comphead added a commit to comphead/iceberg-rust that referenced this pull request Nov 22, 2026
Predicates are bound to the table schema, but the row filter evaluated
them on batches in the file's physical types. For a file written before
an int -> long, float -> double, or decimal precision promotion,
try_cast_literal cast the literal down to the file type, so an
out-of-range literal became null and dropped every row, and a double
literal was rounded to f32.

Convert the filter columns to the table schema with a
RecordBatchTransformer, as the reader does for its output, and make
try_cast_literal fail instead of returning null. Page-index pruning is
left to apache#3507 and apache#3521.

Part of apache#3122.
apache#3507 merged with Arrow 60 changes: PageIndexEvaluator::eval takes a
RowGroupPageIndex and ColumnIndexBuilder::append takes a nan_count, so
the NaN-bound test now builds its page index with PageIndexBuilder. The
promoted INT32 and FLOAT tests also cover the inequality operators that
apache#3507 added.
@rich7420
rich7420 marked this pull request as ready for review November 23, 2026 06:13
Copilot AI balanced review requested due to automatic review settings November 23, 2026 06:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

hcrosse pushed a commit to hcrosse/iceberg-rust that referenced this pull request Nov 23, 2026
…che#3540)

* fix(reader): keep matching rows when filtering a promoted column

Predicates are bound to the table schema, but the row filter evaluated
them on batches in the file's physical types. For a file written before
an int -> long, float -> double, or decimal precision promotion,
try_cast_literal cast the literal down to the file type, so an
out-of-range literal became null and dropped every row, and a double
literal was rounded to f32.

Convert the filter columns to the table schema with a
RecordBatchTransformer, as the reader does for its output, and make
try_cast_literal fail instead of returning null. Page-index pruning is
left to apache#3507 and apache#3521.

Part of apache#3122.

* test(reader): cover files without field ids and date promotion; name the strict cast

Reuse read_once in assert_promoted_reads, read each file with and without a
field id, and add a date -> timestamp case. Explain why try_cast_literal
sets safe: false.

* perf(reader): build the row filter transformer from the filter fields only

The transformer converts its whole schema to Arrow on each file's first
batch. Give it a schema of the top-level filter fields so that setup no
longer grows with the table's width.

* fix(reader): build the row filter schema from each leaf's top-level field

A filter leaf nested in a struct has no top-level field of its own, so
the filter schema missed it and the transformer failed with `field not
found` once nested predicates reach the row filter (apache#2906). Take each
leaf's top-level field, prune it to the filter leaves, and pass the
top-level ids in leaf order.

* fix(reader): reject a filter leaf that is not in the scan schema

filter_schema skipped a leaf without an accessor in the scan schema, so
the converted filter batch had fewer columns than the predicate's column
positions, and the predicate panicked with an index out of bounds. Only
a task whose predicate was bound to another schema gets there. Fail with
DataInvalid instead, as validate_equality_ids does for equality deletes
and the row group evaluator does with default options.

* fix(spec): return an empty struct from prune_columns for an empty selection

PruneColumn::schema unwrapped the visited struct, so selecting nothing
panicked before prune_columns reached its fallback to an empty struct.
Return the value as is, so the fallback applies.

* refactor(reader): simplify the row filter schema and its tests

- filter_schema returns only the schema. The transformer's root ids are
  its top-level fields, and the empty-selection guard is gone now that
  prune_columns handles it.
- Use invalid_data! for the unknown-leaf error, and drop the unused
  schema id.
- try_cast_literal's doc no longer cites Binary and LargeBinary, which
  now map to one Arrow type.
- test_predicate_converter_rejects_lossy_literal_cast reuses
  apply_predicate_to_batch, which now takes the file's message type and
  returns the predicate's result.
- test_predicate_on_promoted_column keeps one case per promotion. The
  dropped cases passed or failed together with the kept ones under every
  mutation of the row filter.

This branch has not been deployed

No deployments
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.

2 participants