From 24ee104b800cb2b07438ed2e843ad3c88a746a58 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Fri, 13 Sep 2024 16:12:55 -0400 Subject: [PATCH] Minor: add `ListingOptions::with_file_extension_opt` --- .../core/src/datasource/listing/table.rs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/datafusion/core/src/datasource/listing/table.rs b/datafusion/core/src/datasource/listing/table.rs index 9246226d431e..e9e3330e298d 100644 --- a/datafusion/core/src/datasource/listing/table.rs +++ b/datafusion/core/src/datasource/listing/table.rs @@ -245,6 +245,7 @@ impl ListingOptions { /// Set file extension on [`ListingOptions`] and returns self. /// + /// # Example /// ``` /// # use std::sync::Arc; /// # use datafusion::prelude::SessionContext; @@ -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(mut self, file_extension: Option) -> Self + where S: Into + { + 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