Skip to content

Dynamic filter pushdown into IcebergTableScan #68

Open

Description

@jverhoeks

Moved from apache/iceberg-rust#2376 at the suggestion of @alexanderbianchi, now that the DataFusion integration lives here.

Is your feature request related to a problem or challenge?

IcebergTableScan (crates/datafusion/src/read/scan.rs) does not take part in DataFusion's dynamic filter pushdown. The filters that HashJoinExec builds at execution time never reach the Iceberg scan. Probe-side scans like lineitem therefore can't prune row groups using the build side's join keys.

Example: TPC-H q14 (lineitem JOIN part ON l_partkey = p_partkey) at SF10. Even with enable_dynamic_filter_pushdown, parquet.pushdown_filters, parquet.reorder_filters and parquet.bloom_filter_on_read all on, lineitem is scanned in full. The dynamic filter is only evaluated row by row in the FilterExec above the scan, which doesn't skip any row groups. On the same data, Trino's Iceberg connector runs this query about 5x faster. Trino samples its DynamicFilter once per split and feeds it into row-group statistics and bloom filters before reading any data.

The scan takes filters: &[Expr] once and converts them into a single static Predicate. Nothing feeds it a predicate that only becomes useful mid-execution.

Describe the solution you'd like

Two layers:

1. In this repo: IcebergTableScan implements gather_filters_for_pushdown / handle_child_pushdown_result, accepts DynamicFilterPhysicalExprs from parent joins, and translates them to Iceberg Predicates through the existing expr_to_predicate path. The current soundness rule still applies: the predicate only has to be implied by the filter, and unconvertible parts are dropped.

2. In iceberg-rust: a hook that samples the dynamic predicate once per FileScanTask, along these lines:

pub trait DynamicPredicate: Send + Sync {
    /// Called right before a FileScanTask opens its Parquet file.
    /// None = not selective yet (e.g. build side not finished).
    fn current(&self) -> Option<Predicate>;
}

impl TableScanBuilder {
    pub fn with_dynamic_predicate(self, dp: Arc<dyn DynamicPredicate>) -> Self;
}

ArrowReader::process_file_scan_task would AND the result with the static predicate. From there it flows into the row filter, row-group pruning and page-index selection that the reader already supports.

Until (2) lands, (1) can apply the filters per batch after decode. That is already a win, but it doesn't reach row-group pruning.

Results from a downstream prototype

  • Per-batch only (layer 1): -21% total TPC-H time at SF1, -9.4% at SF10.
  • Per-task DynamicPredicate (both layers): -12.4% at SF10, all 22 queries returning matching results.

Open problem: caching the bound predicate across tasks

Each FileScanTask pays for conversion plus Predicate::bind. For a hash-join probe set of about 580K keys (q04 at SF10), bind takes about 61 ms and conversion about 19 ms. With about 88 lineitem files and parallelism 12, that's roughly 560 ms of wall-clock per scan.

I tried five cache designs and all of them regressed: Mutex + Arc::ptr_eq, OnceLock, IN-list caps of 4096 and 200, and per-filter Mutex<CachedBound>. Each failed in one of three ways:

  • DynamicFilterPhysicalExpr::current() calls remap_children, which returns a new Arc on the join pushdown path. Pointer-equality caches never hit.
  • In multi-join scans the filters seal at different times. A first-non-None cache locks in a partial predicate. That cost q04 +34%, q06 +74% and q16 +42%.
  • Locking on every per-task call adds contention across concurrent scan tasks.

A correct cache needs DataFusion to tell consumers when a filter's state has changed and when it is final. That could be an is_sealed() or a monotonic generation() on DynamicFilterPhysicalExpr. If that's the right direction, I can open a matching issue in apache/datafusion.

Willingness to contribute

Yes. I can open a PR for layer 1 here, and a PR in iceberg-rust for the DynamicPredicate hook.

Activity

  1. alexanderbianchi commented on Oct 12, 2026

    @alexanderbianchi
    Contributor

    apache/iceberg-rust#3343 cc: @unikdahal. I believe the dynamic predicate hook is already being worked on. also FYI IcebergTableScan is now a DataSource feeding DataSourceExec.

  2. unikdahal commented on Oct 12, 2026

    @unikdahal

    Thanks @jverhoeks for the detailed write-up, and @alexanderbianchi for the cc. This overlaps a lot with what I've been working on, so here are a few notes. Fair warning: I'm about to be away for roughly a month, so please don't wait on me for any of this.

    On the iceberg-rust hook (layer 2). apache/iceberg-rust#3351 is very close to the DynamicPredicate trait you sketched. A RuntimePredicateProvider is sampled when each FileScanTask starts, and its predicate is combined with the planned one. From there it feeds the existing row-group, page-index and row-filter paths. The main difference is that the provider exposes a cheap generation() next to snapshot(), so the reader can cache the bound predicate per generation instead of per task. It hasn't been reviewed yet, so feel free to take it over, rework it, or replace it with your design. I won't mind at all.

    On the caching problem. I don't think this needs a new DataFusion API:

    • The free function datafusion_physical_expr_common::physical_expr::snapshot_generation(&expr) already returns a generation for a whole expression tree, adding up the generations of any dynamic filters inside it. Static expressions contribute 0.
    • DynamicFilterPhysicalExpr::update() bumps the generation. wait_complete() tells you when a filter is final (and wait_update() when it next changes).
    • Since DataFusion 55, current() caches the remapped expression per generation, so it should return the same Arc until the filter changes. If your prototype predates 55, that may explain the pointer-equality misses.

    What worked in my Comet prototype, which attaches one join filter per Iceberg scan:

    1. Read the generation, take current(), then read the generation again. Only use the snapshot if both reads match, because an update can land between them.
    2. Convert and bind once per (generation, schema, case sensitivity) and share the result across all tasks of the scan. In #3351 the cache sits behind a Mutex; my later version switched to an RwLock so a cache hit only takes a read lock.

    Two more suggestions, which I haven't tested myself:

    1. For scans that receive filters from several joins, key the cache on the summed generation of the whole filter expression rather than on the first non-None value. When a later join publishes its filter, the sum changes and the cache refreshes, so a partial predicate never gets locked in.
    2. On the ~580K-key probe set: with DataFusion's defaults (hash_join_inlist_pushdown_max_distinct_values = 150, hash_join_inlist_pushdown_max_size = 128 KiB), the join doesn't push an IN list that large. Past the cap it publishes min/max bounds together with a HashTableLookupExpr. The Iceberg translation can keep the bounds and drop the hash lookup, since the join still verifies every match, and that avoids binding a huge list for each task. If you do want to keep large lists, it helps to have a hash-based membership check in the row filter, since one comparison per literal gets expensive at that size.

    Soundness notes. Treat a failure to convert, bind or evaluate a runtime predicate as "skip it", never as a query error, and never let it bypass delete handling. Be careful with float columns, where NaN and ±0 can make statistics and row evaluation disagree.

    Layer 1 on top of the new IcebergDataSource (#50) sounds like a good first step either way. I'm happy to review when I'm back, if it's still open then.

  3. Perseus commented on Nov 1, 2026

    @Perseus
    Contributor

    👋 @jverhoeks Is this something that you are actively working on? We have some use-cases that would improve with dynamic filtering, and would love to collaborate on this and help push it through.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions