Skip to content

feat: add SchemaProvider::table_type(table_name: &str) #16401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions datafusion/catalog/src/information_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,14 @@ impl InformationSchemaConfig {
// schema name may not exist in the catalog, so we need to check
if let Some(schema) = catalog.schema(&schema_name) {
for table_name in schema.table_names() {
if let Some(table) = schema.table(&table_name).await? {
if let Some(table_type) =
schema.table_type(&table_name).await?
{
builder.add_table(
&catalog_name,
&schema_name,
&table_name,
table.table_type(),
table_type,
);
}
}
Expand Down
11 changes: 11 additions & 0 deletions datafusion/catalog/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use std::sync::Arc;

use crate::table::TableProvider;
use datafusion_common::Result;
use datafusion_expr::TableType;

/// Represents a schema, comprising a number of named tables.
///
Expand Down Expand Up @@ -54,6 +55,16 @@ pub trait SchemaProvider: Debug + Sync + Send {
name: &str,
) -> Result<Option<Arc<dyn TableProvider>>, DataFusionError>;

/// Retrieves the type of a specific table from the schema by name, if it exists, otherwise
/// returns `None`. Implementations for which this operation is cheap but [Self::table] is
/// expensive can override this to improve operations that only need the type, e.g.
/// `SELECT * FROM information_schema.tables`.
async fn table_type(&self, name: &str) -> Result<Option<TableType>> {
self.table(name)
.await
.and_then(|o| Ok(o.map(|t| t.table_type())))
}

/// If supported by the implementation, adds a new table named `name` to
/// this schema.
///
Expand Down