Skip to content

Commit

Permalink
Minor: add ListingOptions::with_file_extension_opt (#12461)
Browse files Browse the repository at this point in the history
* Minor: add `ListingOptions::with_file_extension_opt`

* fmt
  • Loading branch information
alamb authored Sep 14, 2024
1 parent 3dcd9bf commit 88b5970
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 88b5970

Please sign in to comment.