Skip to content

Commit 481aee9

Browse files
committed
fix: simplify the logic
1 parent 973b7b2 commit 481aee9

File tree

1 file changed

+8
-23
lines changed
  • datafusion/core/src/execution/context

1 file changed

+8
-23
lines changed

datafusion/core/src/execution/context/mod.rs

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -837,16 +837,6 @@ impl SessionContext {
837837
.insert(f.name.clone(), Arc::new(f));
838838
}
839839

840-
/// Heuristically determines the format (e.g. parquet, csv) to use with the `table_paths`
841-
fn infer_types(table_paths: &[ListingTableUrl]) -> Option<String> {
842-
let extension = table_paths[0]
843-
.prefix()
844-
.filename()
845-
.map(|filename| filename.split('.').skip(1).collect::<Vec<&str>>().join("."))
846-
.unwrap_or("".to_owned());
847-
Some(extension)
848-
}
849-
850840
/// Creates a [`DataFrame`] for reading a data source.
851841
///
852842
/// For more control such as reading multiple files, you can use
@@ -866,19 +856,14 @@ impl SessionContext {
866856
return exec_err!("No table paths were provided");
867857
}
868858

869-
let extension = Self::infer_types(&table_paths).unwrap();
870-
// some the file extension might be started with "." and some not
871-
let extension_alternative = ".".to_string() + extension.as_str();
872-
873-
if option_extension != extension
874-
&& option_extension != extension_alternative
875-
&& !extension.is_empty()
876-
{
877-
return exec_err!(
878-
"File extension '{}' does not match the expected extension '{}'",
879-
extension,
880-
option_extension
881-
);
859+
// check if the file extension matches the expected extension
860+
for path in &table_paths {
861+
if !path.as_str().ends_with(&option_extension) {
862+
let file_name = path.prefix().filename().unwrap_or_default();
863+
return exec_err!(
864+
"File '{file_name}' does not match the expected extension '{option_extension}'"
865+
);
866+
}
882867
}
883868

884869
let resolved_schema = options

0 commit comments

Comments
 (0)