Skip to content

Commit 413bbab

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 79f5c8d commit 413bbab

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

datafusion/catalog/src/information_schema.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,14 @@ impl InformationSchemaConfig {
103103
// schema name may not exist in the catalog, so we need to check
104104
if let Some(schema) = catalog.schema(&schema_name) {
105105
for table_name in schema.table_names() {
106-
if let Some(table) = schema.table(&table_name).await? {
106+
if let Some(table_type) =
107+
schema.table_type(&table_name).await?
108+
{
107109
builder.add_table(
108110
&catalog_name,
109111
&schema_name,
110112
&table_name,
111-
table.table_type(),
113+
table_type,
112114
);
113115
}
114116
}

datafusion/catalog/src/schema.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use std::sync::Arc;
2626

2727
use crate::table::TableProvider;
2828
use datafusion_common::Result;
29+
use datafusion_expr::TableType;
2930

3031
/// Represents a schema, comprising a number of named tables.
3132
///
@@ -54,6 +55,14 @@ pub trait SchemaProvider: Debug + Sync + Send {
5455
name: &str,
5556
) -> Result<Option<Arc<dyn TableProvider>>, DataFusionError>;
5657

58+
/// Retrieves the type of a specific table from the schema by name, if it exists, otherwise
59+
/// returns `None`. Implementations for which this operation is cheap but [Self::table] is
60+
/// expensive can override this to improve operations that only need the type, e.g.
61+
/// `SELECT * FROM information_schema.tables`.
62+
async fn table_type(&self, name: &str) -> Result<Option<TableType>> {
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
///

0 commit comments

Comments
 (0)