Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve UX Rename FileScanConfig::new_exec to FileScanConfig::build #14670

Merged
merged 3 commits into from
Feb 15, 2025

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Feb 14, 2025

Which issue does this PR close?

Rationale for this change

This was something I noticed while trying to upgrade InfluxDB IOx to use the new APIs introduced in #14224

I would like to make it easier when someone using these APIs upgrades

What changes are included in this PR?

  1. Rename new_exec->build`
  2. Change it to take self rather than force a clone

Are these changes tested?

Are there any user-facing changes?

There are some changes to APIs that are not yet released

@github-actions github-actions bot added core Core DataFusion crate substrait proto Related to proto crate labels Feb 14, 2025
@@ -504,7 +504,7 @@ impl TableProvider for IndexTableProvider {
.with_file(partitioned_file);

// Finally, put it all together into a DataSourceExec
Ok(file_scan_config.new_exec())
Ok(file_scan_config.build())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is basically the change -- use build rather than new_exec which I think is more consistent with the style of code in the rest of this crate (and the Rust builder style in general)

_filters: Option<&Arc<dyn PhysicalExpr>>,
) -> Result<Arc<dyn ExecutionPlan>> {
conf = conf.with_source(Arc::new(ArrowSource::default()));
Ok(conf.new_exec())
Ok(conf.with_source(Arc::new(ArrowSource::default())).build())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

dive by cleanup to avoid mut and make it more concise

@@ -252,19 +257,20 @@ impl DataSource for FileScanConfig {
// If there is any non-column or alias-carrier expression, Projection should not be removed.
// This process can be moved into CsvExec, but it would be an overlap of their responsibility.
Ok(all_alias_free_columns(projection.expr()).then(|| {
let mut file_scan = self.clone();
let file_scan = self.clone();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously calling new_exec always cloned. Now it is only cloned when necessary

pub fn new_exec(&self) -> Arc<DataSourceExec> {
Arc::new(DataSourceExec::new(Arc::new(self.clone())))
/// Returns a new [`DataSourceExec`] to scan the files specified by this config
pub fn build(self) -> Arc<DataSourceExec> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed and changed to take self rather than &self

@@ -93,6 +96,8 @@ pub fn wrap_partition_value_in_dict(val: ScalarValue) -> ScalarValue {
/// PartitionedFile::new("file2.parquet", 56),
/// PartitionedFile::new("file3.parquet", 78),
/// ]);
/// // create an execution plan from the config
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also tried to add some docs that could make build easier to discover

Copy link
Member

@xudong963 xudong963 left a comment

Choose a reason for hiding this comment

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

Nice 🧹

@xudong963 xudong963 merged commit a2e6c90 into apache:main Feb 15, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate proto Related to proto crate substrait
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants