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

Minor: add ListingOptions::with_file_extension_opt #12461

Merged
merged 2 commits into from
Sep 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading