Skip to content

Commit 8a9bf43

Browse files
committed
Improve ListingTableUrl
1 parent 8ac2922 commit 8a9bf43

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

datafusion/core/src/datasource/listing_table_factory.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ impl TableProviderFactory for ListingTableFactory {
161161
}
162162
None => format!("*.{}", cmd.file_type.to_lowercase()),
163163
};
164-
table_path = table_path
165-
.with_glob(glob.as_ref())?
166-
.with_table_ref(cmd.name.clone());
164+
table_path = table_path.with_glob(glob.as_ref())?;
167165
}
168166
let schema = options.infer_schema(session_state, &table_path).await?;
169167
let df_schema = Arc::clone(&schema).to_dfschema()?;

datafusion/datasource/src/url.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub struct ListingTableUrl {
4242
prefix: Path,
4343
/// An optional glob expression used to filter files
4444
glob: Option<Pattern>,
45-
45+
/// Optional table reference for the table this url belongs to
4646
table_ref: Option<TableReference>,
4747
}
4848

@@ -340,17 +340,19 @@ impl ListingTableUrl {
340340
}
341341

342342
/// Returns a copy of current [`ListingTableUrl`] with a specified `glob`
343-
pub fn with_glob(self, glob: &str) -> Result<Self> {
344-
let glob =
345-
Pattern::new(glob).map_err(|e| DataFusionError::External(Box::new(e)))?;
346-
Self::try_new(self.url, Some(glob))
343+
pub fn with_glob(mut self, glob: &str) -> Result<Self> {
344+
self.glob =
345+
Some(Pattern::new(glob).map_err(|e| DataFusionError::External(Box::new(e)))?);
346+
Ok(self)
347347
}
348348

349+
/// Set the table reference for this [`ListingTableUrl`]
349350
pub fn with_table_ref(mut self, table_ref: TableReference) -> Self {
350351
self.table_ref = Some(table_ref);
351352
self
352353
}
353354

355+
/// Return the table reference for this [`ListingTableUrl`]
354356
pub fn get_table_ref(&self) -> &Option<TableReference> {
355357
&self.table_ref
356358
}

0 commit comments

Comments
 (0)