Repository navigation
feat: push down bare boolean columns as AND/OR operands - #167
Open
dragonknightk wants to merge 1 commit into
Open
dragonknightk wants to merge 1 commit into
dragonknightk wants to merge 1 commit into
Conversation
Closes issue 145 ## Rationale for this change Bare boolean columns were only converted to `col = true` at the top level of a filter and to `col = false` directly under `NOT`. When a boolean column appeared inside an `AND` or `OR` expression (such as `b AND x > 1`, `b OR x > 1`, or `NOT (b AND x > 1)`), `predicate` returned `None` for the column, dropping it from `AND` and disabling pushdown for the whole `OR` or `NOT`. ## What changes are included in this PR? Handle `Expr::Column` directly inside `predicate` by returning `col = true` as `Converted::Exact`, and remove the top-level special case. Because `NULL` matches neither `col` nor `col = true`, both match the same rows, so returning `Exact` keeps negation under `NOT` sound. The existing `NOT col -> col = false` arm is kept instead of falling through to `!(col = true)`. Iceberg rewrites `!(col = true)` to `col != true`, which cannot prune all-true or all-null files via min/max metrics, whereas `col = false` can. ## Are these changes tested? Updated the boolean column unit tests to cover unsplit `AND`, `OR`, nested `AND` inside `OR`, `NOT` over compound expressions, and soundness with unconvertible siblings. Added `EXPLAIN` and result-row checks in `boolean_predicate_pushdown.slt` for `OR` and nested `AND` inside `OR` over rows with `true`, `false`, and `NULL` values. ## Are there any user-facing changes? No public API changes. Queries filtering on bare boolean columns in `OR` or nested `AND` predicates now push those predicates down to Iceberg scans. Signed-off-by: DragonKnightK <37928252+dragonknightk@users.noreply.github.com>
Contributor
|
I'll look at this closer tomorrow. |
NoahKusaba
reviewed
Dec 5, 2026
NoahKusaba
left a comment
Contributor
There was a problem hiding this comment.
Thanks, the approach is right: making a boolean column an ordinary leaf lets AND/OR/NOT handle it with no special case, and dropping convert_filter_to_predicate is the nice part. I checked the soundness of Exact (iceberg-rust's row filter combines with and_kleene/or_kleene) and that the not_eq comment matches InclusiveMetricsEvaluator. Some suggestions to tighten it, all optional:
convert_filters_to_predicatecould be.filter_map(predicate).map(Converted::into_predicate).- The two comments could become one above both arms, since
bandNOT bfollow the same rule. - In the test,
convert_singlegives the same result asconvert_to_iceberg_predicate(splitting the top-level AND and rejoining withPredicate::andbuilds the same tree), and(b and foo > 1) or foo < 0already covers theAndbranch. The three unconvertible-sibling cases testand/or/notthemselves, which_or_condition_unsupportedand_not_of_partial_andalready cover, andnot (b or …)repeatsnot (b and …). What's left fits thefor (sql, expected) in [...]table that_single_condition_revuses, withlet b = |value| Reference::new("b").equal_to(Datum::bool(value));. - In the SLT, the existing
is_active = true OR id = 2query already has this shape after simplification. It only checked rows, which is why the gap went unnoticed, so I'd put theEXPLAINthere instead of adding a second OR plan, keep your NULL-row query, and drop the "(issue 145)" mentions. - FYI, DataFusion's simplifier rewrites
NOT (b AND x)toNOT b OR …before pushdown, so the real-world gains areb OR xand(b AND x) OR y.
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.
Closes #145.
Rationale for this change
Bare boolean columns were only converted to
col = trueat the top level of a filter and tocol = falsedirectly underNOT. When a boolean column appeared inside anANDorORexpression (such asb AND x > 1,b OR x > 1, orNOT (b AND x > 1)),predicatereturnedNonefor the column, dropping it fromANDand disabling pushdown for the wholeORorNOT.What changes are included in this PR?
Handle
Expr::Columndirectly insidepredicateby returningcol = trueasConverted::Exact, and remove the top-level special case. BecauseNULLmatches neithercolnorcol = true, both match the same rows, so returningExactkeeps negation underNOTsound.The existing
NOT col -> col = falsearm is kept instead of falling through to!(col = true). Iceberg rewrites!(col = true)tocol != true, which cannot prune all-true or all-null files via min/max metrics, whereascol = falsecan.Are these changes tested?
Updated the boolean column unit tests to cover unsplit
AND,OR, nestedANDinsideOR,NOTover compound expressions, and soundness with unconvertible siblings. AddedEXPLAINand result-row checks inboolean_predicate_pushdown.sltforORand nestedANDinsideORover rows withtrue,false, andNULLvalues.Are there any user-facing changes?
No public API changes. Queries filtering on bare boolean columns in
ORor nestedANDpredicates now push those predicates down to Iceberg scans.AI Disclosure
Grok Bot, working for dragonknightk, assisted with the changes, the description, and the verification. All content was reviewed by a human, and the submitter understands and can maintain these changes.