Skip to content

Commit fab7e23

Browse files
connecalamb
andauthored
Add CsvExecBuilder for creating CsvExec (#11633)
* 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]>
1 parent dcdcc25 commit fab7e23

File tree

7 files changed

+454
-238
lines changed

7 files changed

+454
-238
lines changed

datafusion/core/src/datasource/file_format/csv.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -344,22 +344,25 @@ impl FileFormat for CsvFormat {
344344
conf: FileScanConfig,
345345
_filters: Option<&Arc<dyn PhysicalExpr>>,
346346
) -> Result<Arc<dyn ExecutionPlan>> {
347-
let exec = CsvExec::new(
348-
conf,
349-
// If format options does not specify whether there is a header,
350-
// we consult configuration options.
351-
self.options
352-
.has_header
353-
.unwrap_or(state.config_options().catalog.has_header),
354-
self.options.delimiter,
355-
self.options.quote,
356-
self.options.escape,
357-
self.options.comment,
358-
self.options
359-
.newlines_in_values
360-
.unwrap_or(state.config_options().catalog.newlines_in_values),
361-
self.options.compression.into(),
362-
);
347+
// Consult configuration options for default values
348+
let has_header = self
349+
.options
350+
.has_header
351+
.unwrap_or(state.config_options().catalog.has_header);
352+
let newlines_in_values = self
353+
.options
354+
.newlines_in_values
355+
.unwrap_or(state.config_options().catalog.newlines_in_values);
356+
357+
let exec = CsvExec::builder(conf)
358+
.with_has_header(has_header)
359+
.with_delimeter(self.options.delimiter)
360+
.with_quote(self.options.quote)
361+
.with_escape(self.options.escape)
362+
.with_comment(self.options.comment)
363+
.with_newlines_in_values(newlines_in_values)
364+
.with_file_compression_type(self.options.compression.into())
365+
.build();
363366
Ok(Arc::new(exec))
364367
}
365368

0 commit comments

Comments
 (0)