Skip to content

Move statistics handling into FileScanConfig - #18721

Merged
adriangb merged 6 commits into
apache:mainfrom
pydantic:projection-source-stats
Nov 20, 2025
Merged

Move statistics handling into FileScanConfig#18721
adriangb merged 6 commits into
apache:mainfrom
pydantic:projection-source-stats

Conversation

@adriangb

@adriangbadriangb commented Nov 14, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR moves statistics handling from individual FileSource implementations into FileScanConfig, simplifying the FileSource trait interface.
The FileSources were all acting as a container for the statistics but never actually using them.
Since FileScanConfig deals with file-level things (which the statistics are) it is better equipped to deal with it.

Changes

  • FileSource trait simplification: Removed statistics(), with_statistics(), and with_projection() methods
  • FileScanConfig enhancement: Added statistics field and statistics() method
  • FileSource implementations updated: Removed projected_statistics field from all implementations:
    • ParquetSource
    • CsvSource
    • JsonSource
    • AvroSource
    • ArrowFileSource and ArrowStreamFileSource
    • MockSource (test utility)
  • Test utilities: Updated assertions to use config.statistics() instead of file_source.statistics()
  • Proto serialization: Updated to use config.statistics()

Benefits

  1. Simpler trait interface: FileSource implementations no longer need to manage statistics
  2. Centralized statistics: All statistics are now managed consistently in FileScanConfig
  3. Cleaner API: Statistics lifecycle is clearer and less error-prone
  4. Reduced code duplication: Removes ~140 lines of boilerplate across implementations

Related

This is part of the projection refactoring work in #18627. This PR extracts just the statistics-related changes to make review easier. The full projection refactoring will come in subsequent PRs.

Test plan

  • All modified file source implementations compile
  • Test utilities updated and compile
  • CI tests pass (will verify after PR creation)

🤖 Generated with Claude Code

@github-actionsgithub-actionsBot added core Core DataFusion crate proto Related to proto crate datasource Changes to the datasource crate labels Nov 14, 2025
@adriangb
adriangbforce-pushed the projection-source-stats branch from b84171f to e2d7126CompareNovember 15, 2025 00:49
@adriangb
adriangb marked this pull request as draft November 15, 2025 00:50
@adriangb
adriangbforce-pushed the projection-source-stats branch from e2d7126 to 5ebc343CompareNovember 15, 2025 07:14
@adriangb
adriangb marked this pull request as ready for review November 15, 2025 07:16
Comment on lines +747 to +753
pub fn statistics(&self) -> Statistics {
if self.file_source.filter().is_some() {
self.statistics.clone().to_inexact()
} else {
self.statistics.clone()
}
}

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Now we don't have to rely on each FileSource to remember to do this 😄

Comment threaddatafusion/datasource/src/file_scan_config.rs Outdated
Comment threaddatafusion/datasource/src/file_scan_config.rs Outdated
Comment threaddatafusion/datasource/src/file_scan_config.rs Outdated
@adriangb
adriangbforce-pushed the projection-source-stats branch from 317486b to c672a73CompareNovember 17, 2025 22:26
@adriangb
adriangbforce-pushed the projection-source-stats branch 2 times, most recently from 2dbfd1e to ccb4e69CompareNovember 17, 2025 22:30

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change

@xudong963
xudong963 self-requested a review November 18, 2025 09:46
@adriangb
adriangb disabled auto-merge November 18, 2025 13:02
@adriangb
adriangbforce-pushed the projection-source-stats branch from a9c8746 to 0ad47a0CompareNovember 19, 2025 10:39

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

I'm not a maintainer, but LGTM

adriangband others added 3 commits November 20, 2025 06:42
Co-authored-by: Martin Grigorov <martin-g@users.noreply.github.com>
@adriangb
adriangbforce-pushed the projection-source-stats branch from 0ad47a0 to dc3e9dbCompareNovember 19, 2025 22:42
@alambalamb added the api change Changes the API exposed to users of the crate label Nov 20, 2025

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

Looks good to me -- thank you @adriangb@martin-g and @leoyvens

I think we should add a note to the upgrade guide, but otherwise this PR looks ready to merge to me

}
}

pub fn projected_stats(&self) -> Statistics {

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.

I think this is a (small) public API change, so we should flag this PR thusly (I did) and add a note to the upgrade guide

pub expr_adapter_factory: Option<Arc<dyn PhysicalExprAdapterFactory>>,
/// Unprojected statistics for the table (file schema + partition columns).
/// These are projected on-demand via `projected_stats()`.
pub(crate) statistics: Statistics,

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.

nit is that this field has a different visibility (pub(crate)) than all the other fields

write!(
f,
"statistics={:?}, ",
self.file_source.statistics().unwrap()

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.

removing an unwrap in the display certainly seems like an improvement to me

@github-actionsgithub-actionsBot added the documentation Improvements or additions to documentation label Nov 20, 2025
@adriangb
adriangb added this pull request to the merge queueNov 20, 2025
Merged via the queue into apache:main with commit 8a91db5Nov 20, 2025
29 checks passed
logan-keede pushed a commit to logan-keede/datafusion that referenced this pull request Nov 23, 2025
## Summary
This PR moves statistics handling from individual `FileSource`
implementations into `FileScanConfig`, simplifying the `FileSource`
trait interface.
The `FileSource`s were all acting as a container for the statistics but
never actually using them.
Since `FileScanConfig` deals with file-level things (which the
statistics are) it is better equipped to deal with it.
### Changes
- **FileSource trait simplification**: Removed `statistics()`,
`with_statistics()`, and `with_projection()` methods
- **FileScanConfig enhancement**: Added `statistics` field and
`statistics()` method
- **FileSource implementations updated**: Removed `projected_statistics`
field from all implementations:
- ParquetSource
- CsvSource - JsonSource
- AvroSource
- ArrowFileSource and ArrowStreamFileSource
- MockSource (test utility)
- **Test utilities**: Updated assertions to use `config.statistics()`
instead of `file_source.statistics()`
- **Proto serialization**: Updated to use `config.statistics()`
### Benefits
1. **Simpler trait interface**: `FileSource` implementations no longer
need to manage statistics
2. **Centralized statistics**: All statistics are now managed
consistently in `FileScanConfig`
3. **Cleaner API**: Statistics lifecycle is clearer and less error-prone
4. **Reduced code duplication**: Removes ~140 lines of boilerplate
across implementations
### Related
This is part of the projection refactoring work in apache#18627. This PR
extracts just the statistics-related changes to make review easier. The
full projection refactoring will come in subsequent PRs.
## Test plan
- [x] All modified file source implementations compile
- [x] Test utilities updated and compile - [x] CI tests pass (will verify after PR creation)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Martin Grigorov <martin-g@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api changeChanges the API exposed to users of the cratecoreCore DataFusion cratedatasourceChanges to the datasource cratedocumentationImprovements or additions to documentationprotoRelated to proto crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@adriangb@martin-g@alamb@leoyvens