Skip to content

Commit

Permalink
Minor: add ListingOptions::with_file_extension_opt
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Sep 13, 2024
1 parent 389f7f7 commit 24ee104
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions datafusion/core/src/datasource/listing/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ impl ListingOptions {

/// Set file extension on [`ListingOptions`] and returns self.
///
/// # Example
/// ```
/// # use std::sync::Arc;
/// # use datafusion::prelude::SessionContext;
Expand All @@ -262,6 +263,33 @@ impl ListingOptions {
self
}

/// Optionally set file extension on [`ListingOptions`] and returns self.
///
/// If `file_extension` is `None`, the file extension will not be changed
///
/// # Example
/// ```
/// # use std::sync::Arc;
/// # use datafusion::prelude::SessionContext;
/// # use datafusion::datasource::{listing::ListingOptions, file_format::parquet::ParquetFormat};
/// let extension = Some(".parquet");
/// let listing_options = ListingOptions::new(Arc::new(
/// ParquetFormat::default()
/// ))
/// .with_file_extension_opt(extension);
///
/// assert_eq!(listing_options.file_extension, ".parquet");
/// ```
pub fn with_file_extension_opt<S>(mut self, file_extension: Option<S>) -> Self
where S: Into<String>
{
if let Some(file_extension) = file_extension {
self.file_extension = file_extension.into();
}
self
}


/// Set `table partition columns` on [`ListingOptions`] and returns self.
///
/// "partition columns," used to support [Hive Partitioning], are
Expand Down

0 comments on commit 24ee104

Please sign in to comment.