Skip to content

feat: push down bare boolean columns as AND/OR operands - #167

Open
dragonknightk wants to merge 1 commit into
apache:mainfrom
dragonknightk:feat/issue-145-boolean-column-pushdown
Open

dragonknightk wants to merge 1 commit into
apache:mainfrom
dragonknightk:feat/issue-145-boolean-column-pushdown

Conversation

@dragonknightk

Copy link
Copy Markdown

Closes #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.

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.

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>
@NoahKusaba

Copy link
Copy Markdown
Contributor

I'll look at this closer tomorrow.

@NoahKusaba NoahKusaba left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_predicate could be .filter_map(predicate).map(Converted::into_predicate).
  • The two comments could become one above both arms, since b and NOT b follow the same rule.
  • In the test, convert_single gives the same result as convert_to_iceberg_predicate (splitting the top-level AND and rejoining with Predicate::and builds the same tree), and (b and foo > 1) or foo < 0 already covers the And branch. The three unconvertible-sibling cases test and/or/not themselves, which _or_condition_unsupported and _not_of_partial_and already cover, and not (b or …) repeats not (b and …). What's left fits the for (sql, expected) in [...] table that _single_condition_rev uses, with let b = |value| Reference::new("b").equal_to(Datum::bool(value));.
  • In the SLT, the existing is_active = true OR id = 2 query already has this shape after simplification. It only checked rows, which is why the gap went unnoticed, so I'd put the EXPLAIN there 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) to NOT b OR … before pushdown, so the real-world gains are b OR x and (b AND x) OR y.

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.

Push down a boolean column used as an AND/OR operand

2 participants