Skip to content

feat: push down filters with decimal literals - #173

Open
NoahKusaba wants to merge 1 commit into
apache:mainfrom
NoahKusaba:feat/decimal-predicate-pushdown
Open

NoahKusaba wants to merge 1 commit into
apache:mainfrom
NoahKusaba:feat/decimal-predicate-pushdown

Conversation

@NoahKusaba

@NoahKusaba NoahKusaba commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

@terbed, you mentioned a draft on #73. I'm happy to fold anything from it into this PR, or to review yours instead if you'd rather open it.

Rationale for this change

scalar_value_to_datum didn't convert Decimal128 literals, so a filter on a decimal column was never passed to Iceberg and couldn't skip data files. Decimal filters are common in analytical queries; TPC-H q6, for one, filters on the decimal columns l_discount and l_quantity.

What changes are included in this PR?

Decimal128 literals convert to an Iceberg decimal with the same value, precision and scale. A literal Iceberg can't hold isn't converted, and its filter stays with DataFusion: Arrow allows a negative scale and a value with more digits than its precision, Iceberg neither.

Nothing else is needed for the common SQL forms. DataFusion's unwrap_cast_in_comparison already converts an integer, float or narrower decimal literal to the column's type when the result doesn't change, so price > 1, price > 1.2 and price > CAST('1.2' AS DECIMAL(5, 1)) are all pushed down. A literal it can't convert exactly, such as CAST('1.205' AS DECIMAL(10, 3)) against a DECIMAL(10, 2) column, leaves a cast on the column and isn't pushed down.

The datum is built with Datum::try_from_bytes and checked with Datum::to, because iceberg-rust's Datum::decimal_from_mantissa is private. A TODO notes the cleanup if it becomes public.

Are these changes tested?

Yes.

  • Unit tests in predicate.rs: the literal conversion (negative values, scale kept as in 1.20, the largest 38-digit values, values over their precision, negative scales, NULL), and comparisons and IN lists, including an IN list with a value Iceberg can't hold, which isn't pushed down at all.
  • filter_pushdown::decimal_filters_skip_files: a decimal filter matching one of three files opens only that file.
  • decimal_predicate_pushdown.slt: which SQL forms are pushed down, and the rows returned by each comparison, IN and NOT IN across five data files, including the largest and smallest DECIMAL(10, 2) and DECIMAL(38, 10) values.

The slt uses typed literals for values with seven or more digits before the point. DataFusion casts such float literals to Decimal128(30, 15) inexactly, so price = 99999999.99 matches no rows whatever the table provider (apache/datafusion#28053).

Are there any user-facing changes?

Filters on decimal columns now skip data files. Query results don't change.

Comparisons and IN lists with a Decimal128 literal weren't converted to
Iceberg predicates, so filters on decimal columns never skipped files.

Convert the literal to an Iceberg decimal with the same value, precision
and scale. A literal Iceberg can't hold (a negative scale, or more digits
than its precision) isn't converted, and its filter stays with DataFusion.
Literals DataFusion can't convert exactly to the column's type already
leave a cast on the column, so they aren't pushed down either.

Closes apache#73.
@NoahKusaba
NoahKusaba marked this pull request as ready for review December 6, 2026 01:07
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.

Support Decimal128 literals in predicate pushdown

1 participant