Skip to content

Commit 4872589

Browse files
committed
feat: add SchemaProvider::table_type(table_name: &str)
InformationSchemaConfig::make_tables only needs the TableType not the whole TableProvider, and the former may require an expensive catalog operation to construct and the latter may not. This allows avoiding `SELECT * FROM information_schema.tables` having to make 1 of those potentially expensive operations per table.
1 parent 1c10b8b commit 4872589

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

datafusion/catalog/src/schema.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ pub trait SchemaProvider: Debug + Sync + Send {
5454
name: &str,
5555
) -> Result<Option<Arc<dyn TableProvider>>, DataFusionError>;
5656

57+
/// Retrieves the type of a specific table from the schema by name, if it exists,
58+
/// otherwise returns `None`.
59+
async fn table_type(
60+
&self,
61+
name: &str,
62+
) -> Result<Option<datafusion_expr::TableType>, DataFusionError> {
63+
self.table(name).await.map(|o| o.map(|t| t.table_type()))
64+
}
65+
5766
/// If supported by the implementation, adds a new table named `name` to
5867
/// this schema.
5968
///

datafusion/core/src/catalog_common/information_schema.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,15 @@ impl InformationSchemaConfig {
104104
// schema name may not exist in the catalog, so we need to check
105105
if let Some(schema) = catalog.schema(&schema_name) {
106106
for table_name in schema.table_names() {
107-
if let Some(table) = schema.table(&table_name).await? {
107+
// TODO(epg): Why is it legal for SchemaProvider::table to return None
108+
// for a name returned by SchemaProvider::table_names? Shouldn't we
109+
// assert Some rather than quietly continuing?
110+
if let Some(table_type) = schema.table_type(&table_name).await? {
108111
builder.add_table(
109112
&catalog_name,
110113
&schema_name,
111114
&table_name,
112-
table.table_type(),
115+
table_type,
113116
);
114117
}
115118
}

0 commit comments

Comments
 (0)