Skip to content

Commit

Permalink
Add CsvExecBuilder for creating CsvExec (#11633)
Browse files Browse the repository at this point in the history
* feat: add `CsvExecBuilder`, deprecate `CsvExec::new`

This adds the `CsvExecBuilder` struct for building a `CsvExec` instance,
and deprecates the `CsvExec::new` method which has grown too large.

There are some `TODO`s related to the duplication of formatting options
and their defaults coming from multiple places. Uses of the deprecated
`new` method have not been updated yet.

* chore: replace usage of deprecated `CsvExec::new` with `CsvExec::builder`

* Add test that CSVExec options are the same

* fmt

---------

Co-authored-by: Andrew Lamb <[email protected]>
  • Loading branch information
connec and alamb committed Jul 25, 2024
1 parent dcdcc25 commit fab7e23
Show file tree
Hide file tree
Showing 7 changed files with 454 additions and 238 deletions.
35 changes: 19 additions & 16 deletions datafusion/core/src/datasource/file_format/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,22 +344,25 @@ impl FileFormat for CsvFormat {
conf: FileScanConfig,
_filters: Option<&Arc<dyn PhysicalExpr>>,
) -> Result<Arc<dyn ExecutionPlan>> {
let exec = CsvExec::new(
conf,
// If format options does not specify whether there is a header,
// we consult configuration options.
self.options
.has_header
.unwrap_or(state.config_options().catalog.has_header),
self.options.delimiter,
self.options.quote,
self.options.escape,
self.options.comment,
self.options
.newlines_in_values
.unwrap_or(state.config_options().catalog.newlines_in_values),
self.options.compression.into(),
);
// Consult configuration options for default values
let has_header = self
.options
.has_header
.unwrap_or(state.config_options().catalog.has_header);
let newlines_in_values = self
.options
.newlines_in_values
.unwrap_or(state.config_options().catalog.newlines_in_values);

let exec = CsvExec::builder(conf)
.with_has_header(has_header)
.with_delimeter(self.options.delimiter)
.with_quote(self.options.quote)
.with_escape(self.options.escape)
.with_comment(self.options.comment)
.with_newlines_in_values(newlines_in_values)
.with_file_compression_type(self.options.compression.into())
.build();
Ok(Arc::new(exec))
}

Expand Down
Loading

0 comments on commit fab7e23

Please sign in to comment.