Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The Iceberg data sources (
iceberg/src/lazy/data_source.rs,iceberg/src/eager/data_source.rs) currently reject every filter DataFusion pushes into them (PushedDown::No). As a result, dynamic filters, such as the min/max bounds and IN lists that a hash join builds from its build side, are never used to prune Iceberg scans. iceberg-rust'sArrowReadercan already prune row groups, pages and rows with aniceberg::expr::Predicate. What's missing is a way to turn a DataFusion physical filter expression into such a predicate.This PR adds that converter. Nothing calls it yet; follow-up PRs will wire it into the Iceberg data sources.
What it adds
iceberg/src/common/physical_expr_to_predicate.rs:Conservative rule. The returned predicate matches every row for which
exprcould evaluate totrue. It may match more rows, but never fewer.Nonemeans "no pruning possible". DataFusion still evaluates the original filter, so over-matching only costs pruning opportunity, never correctness.Exact vs approximate. Internally, each converted subtree records whether it is exact (it matches exactly the same rows, with the same NULL semantics) or approximate (it over-matches).
ANDkeeps the children it can convert. If it drops any child, the result becomes approximate. If no child converts, the result isNone.ORconverts only when both children convert exactly. An approximate branch is fine on its own, but combined withNOTabove it, it could under-match.NOTconverts only when its child is exact, because negating an over-approximation gives an under-approximation.Supported shapes
col op literalandliteral op colfor= != < <= > >=. The operator is swapped when the literal is on the left.IS NULL/IS NOT NULLon a column.col IN (...)→is_in. NULL items are skipped (they can never match), and an empty list becomesAlwaysFalse.col NOT IN (...)→is_not_in, only when every item is a non-null, convertible literal.NOT INwith a NULL item never matches in DataFusion, so it isn't converted.true/false→AlwaysTrue/AlwaysFalse.DynamicFilterPhysicalExpris converted from its current value (current()), recursively. This is called per conversion, so updated filter values are picked up.Everything else doesn't convert and is dropped when it appears under
AND: casts,CASE, hash-table lookups, arithmetic, column-vs-column comparisons and unknown expressions. For a hash-join dynamic filter, the bounds and the IN list are therefore kept and the hash/CASErouting is dropped.Columns. A
Columnresolves only when the input-schema field atcolumn.index()exists and has the same name as the column, and that name exists in the Iceberg schema. The index is what DataFusion actually evaluates, so a name that disagrees with it is not trusted.Literals. Mapped types: bool, int8/16/32 →
int, int64 →long, float32/float64, utf8 / large utf8 / utf8view, date32, and timestamps (seconds and milliseconds converted exactly to microseconds with overflow checks; microseconds; nanoseconds; tz →timestamptz*). The datum's type must equal the Iceberg field's primitive type exactly. No widening or narrowing (for example, an int32 literal against alongcolumn doesn't convert), so there's no risk of lossy coercion. Not converted:+0.0/-0.0. DataFusion distinguishes the two, while Iceberg may treat them as equal (for example in IN sets), which could under-match.Testing
16 unit tests next to the implementation, using inline
instasnapshots of the rendered predicate. They cover:ANDpartial dropOR/NOTrejecting approximate childrenINandNOT IN, including NULL itemsupdate()CASErouting expression)Commands run:
cargo fmt --allcargo clippy -p datafusion-distributed-iceberg --all-targets: no warnings in this cratecargo test -p datafusion-distributed-iceberg: all pass