Skip to content

refactor: replace IcebergDataSource::new_with_predicate with a builder - #63

Merged
gabotechs merged 1 commit into
apache:mainfrom
NoahKusaba:feat/data-source-builder
Oct 12, 2026
Merged

gabotechs merged 1 commit into
apache:mainfrom
NoahKusaba:feat/data-source-builder

Conversation

@NoahKusaba

@NoahKusaba NoahKusaba commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

#20 made IcebergDataSource::new_with_predicate public so that a codec can rebuild a scan from its accessors. It takes every part of the scan as a positional argument. A scan option added later would mean adding an argument, which is a breaking change. A builder lets new options be added without breaking callers.

What changes are included in this PR?

  • Replaces IcebergDataSource::new_with_predicate with IcebergDataSource::builder(table, schema), exported from iceberg_datafusion::read as IcebergDataSourceBuilder. It has these setters:

    • with_projection(Option<&Vec<usize>>): selects columns of schema by index, as TableProvider::scan passes them.
    • with_snapshot_id(Option<i64>)
    • with_filters(&[Expr]): converts DataFusion filters to an Iceberg predicate.
    • with_predicate(Option<Predicate>): sets an already-converted predicate.
    • with_fetch(Option<usize>)

    The Option setters let a codec pass the accessors' values straight through. build() returns a Result, because a projection index can be out of range.

    IcebergDataSource::builder(scan.table().clone(), scan.schema())
        .with_snapshot_id(scan.snapshot_id())
        .with_predicate(scan.predicate().cloned())
        .with_fetch(scan.fetch())
        .build()?
  • Removes the crate-internal positional constructor IcebergDataSource::new. Both table providers now build their scans with the builder.

  • Renames the accessor predicates() to predicate(), since it returns a single Predicate.

Are there any user-facing changes?

Yes. IcebergDataSource::new_with_predicate is removed in favor of the builder, and IcebergDataSource::predicates() is renamed to predicate(). Both were added in #20 and aren't in any release.

Are these changes tested?

Yes.

  • The integration tests that rebuild a scan from its accessors now use the builder, including the scan built over part of the table's columns.
  • A unit test checks that with_projection returns columns in the projection's order and rejects an out-of-range index.
  • Every provider scan goes through the builder, so the existing scan tests cover it too.

Comment thread crates/datafusion/src/read/scan.rs
Comment thread crates/datafusion/src/read/scan.rs Outdated
@NoahKusaba
NoahKusaba force-pushed the feat/data-source-builder branch from 4fd759e to cec4bf7 Compare October 11, 2026 17:13
@NoahKusaba NoahKusaba changed the title refactor: build IcebergDataSource with a builder refactor: replace IcebergDataSource::new_with_predicate with a builder Oct 11, 2026
@NoahKusaba
NoahKusaba force-pushed the feat/data-source-builder branch from cec4bf7 to 1cd1ec2 Compare October 11, 2026 17:43
@NoahKusaba
NoahKusaba requested a review from gabotechs October 11, 2026 17:45

@gabotechs gabotechs 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.

👍 nice, thanks @NoahKusaba!

@gabotechs
gabotechs merged commit 5d0dd98 into apache:main Oct 12, 2026
5 checks passed
@NoahKusaba
NoahKusaba deleted the feat/data-source-builder branch October 12, 2026 13:28
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.

2 participants