This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-rust.git
The following commit(s) were added to refs/heads/main by this push:
new 22025830 feat(datafusion): support scoped and filtered metadata
listings (#1278)
22025830 is described below
commit 22025830c747c32d625d75f4380ea5ce3b695244
Author: Jingsong Lee <[email protected]>
AuthorDate: Sun Nov 1 23:49:46 2026 +0800
feat(datafusion): support scoped and filtered metadata listings (#1278)
---
crates/integrations/datafusion/src/catalog.rs | 44 ++++
crates/integrations/datafusion/src/lib.rs | 1 +
.../integrations/datafusion/src/show_metadata.rs | 252 +++++++++++++++++++++
crates/integrations/datafusion/src/sql_context.rs | 40 +---
.../datafusion/tests/sql_context_tests.rs | 234 ++++++++++++++++++-
docs/src/sql.md | 27 +++
6 files changed, 562 insertions(+), 36 deletions(-)
diff --git a/crates/integrations/datafusion/src/catalog.rs
b/crates/integrations/datafusion/src/catalog.rs
index d6227c4b..5b42b440 100644
--- a/crates/integrations/datafusion/src/catalog.rs
+++ b/crates/integrations/datafusion/src/catalog.rs
@@ -643,6 +643,50 @@ impl CatalogProvider for PaimonCatalogProvider {
}
impl PaimonCatalogProvider {
+ /// List one namespace without loading persistent table providers or
losing catalog errors.
+ pub(super) async fn table_metadata(
+ &self,
+ database: &str,
+ ) -> DFResult<Vec<(String, TableType)>> {
+ let temp = self
+ .temp_tables
+ .read()
+ .unwrap_or_else(|e| e.into_inner())
+ .get(database)
+ .cloned();
+ let mut tables = HashMap::new();
+ match self.catalog.get_database(database).await {
+ Ok(_) => {
+ for name in self
+ .catalog
+ .list_tables(database)
+ .await
+ .map_err(to_datafusion_error)?
+ {
+ tables.insert(name, TableType::Base);
+ }
+ let views = match self.catalog.list_views(database).await {
+ Ok(views) => views,
+ Err(paimon::Error::Unsupported { .. }) => Vec::new(),
+ Err(error) => return Err(to_datafusion_error(error)),
+ };
+ for name in views {
+ tables.entry(name).or_insert(TableType::View);
+ }
+ }
+ Err(paimon::Error::DatabaseNotExist { .. }) if temp.is_some() => {}
+ Err(error) => return Err(to_datafusion_error(error)),
+ }
+ if let Some(temp) = temp {
+ for name in temp.table_names() {
+ if let Some(table_type) = temp.table_type(&name).await? {
+ tables.insert(name, table_type);
+ }
+ }
+ }
+ Ok(tables.into_iter().collect())
+ }
+
/// Registers a temporary table or view in the specified database.
/// Creates the database if it does not exist.
///
diff --git a/crates/integrations/datafusion/src/lib.rs
b/crates/integrations/datafusion/src/lib.rs
index 050fb7ce..ecc39411 100644
--- a/crates/integrations/datafusion/src/lib.rs
+++ b/crates/integrations/datafusion/src/lib.rs
@@ -62,6 +62,7 @@ mod physical_plan;
mod procedures;
mod relation_planner;
pub mod runtime;
+mod show_metadata;
mod sql_context;
mod sql_function;
mod system_tables;
diff --git a/crates/integrations/datafusion/src/show_metadata.rs
b/crates/integrations/datafusion/src/show_metadata.rs
new file mode 100644
index 00000000..94c34725
--- /dev/null
+++ b/crates/integrations/datafusion/src/show_metadata.rs
@@ -0,0 +1,252 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::collections::HashMap;
+use std::sync::Arc;
+
+use datafusion::arrow::array::{RecordBatch, StringArray};
+use datafusion::arrow::datatypes::{DataType, Field, Schema};
+use datafusion::catalog::information_schema::{INFORMATION_SCHEMA,
INFORMATION_SCHEMA_TABLES};
+use datafusion::datasource::TableType;
+use datafusion::error::{DataFusionError, Result};
+use datafusion::prelude::{col, lit, DataFrame, SessionContext};
+use datafusion::sql::planner::IdentNormalizer;
+use datafusion::sql::sqlparser::ast::{
+ ShowStatementFilter, ShowStatementFilterPosition, ShowStatementOptions,
Statement,
+};
+use paimon::catalog::Catalog;
+
+pub(crate) async fn execute(
+ ctx: &SessionContext,
+ catalogs: &HashMap<String, Arc<dyn Catalog>>,
+ statement: &Statement,
+) -> Result<DataFrame> {
+ let (options, invalid_modifiers, kind) = match statement {
+ Statement::ShowCatalogs {
+ terse,
+ history,
+ show_options,
+ } => (show_options, *terse || *history, "SHOW CATALOGS"),
+ Statement::ShowDatabases {
+ terse,
+ history,
+ show_options,
+ }
+ | Statement::ShowSchemas {
+ terse,
+ history,
+ show_options,
+ } => (show_options, *terse || *history, "SHOW DATABASES"),
+ Statement::ShowTables {
+ terse,
+ history,
+ extended,
+ full,
+ external,
+ show_options,
+ } => (
+ show_options,
+ *terse || *history || *extended || *full || *external,
+ "SHOW TABLES",
+ ),
+ _ => unreachable!("only metadata SHOW statements are dispatched here"),
+ };
+ if invalid_modifiers
+ || options.starts_with.is_some()
+ || options.limit.is_some()
+ || options.limit_from.is_some()
+ {
+ return Err(DataFusionError::Plan(format!(
+ "{kind} options are not supported"
+ )));
+ }
+ let state = ctx.state();
+ let config = &state.config_options().catalog;
+ let normalizer = IdentNormalizer::new(ctx.enable_ident_normalization());
+ let scope = options
+ .show_in
+ .as_ref()
+ .map(|scope| {
+ let name = scope
+ .parent_name
+ .as_ref()
+ .ok_or_else(|| DataFusionError::Plan("SHOW IN requires a
name".into()))?;
+ if scope.parent_type.is_some() {
+ return Err(DataFusionError::Plan(
+ "typed SHOW IN scopes are not supported".into(),
+ ));
+ }
+ name.0
+ .iter()
+ .map(|part| {
+ part.as_ident()
+ .map(|id| normalizer.normalize(id.clone()))
+ .ok_or_else(|| DataFusionError::Plan("SHOW IN requires
identifiers".into()))
+ })
+ .collect::<Result<Vec<_>>>()
+ })
+ .transpose()?;
+ match statement {
+ Statement::ShowCatalogs { .. } => {
+ if scope.is_some() {
+ return Err(DataFusionError::Plan(
+ "SHOW CATALOGS does not accept IN".into(),
+ ));
+ }
+ filter(
+ names_frame(ctx, "catalog_name", ctx.catalog_names())?,
+ options,
+ "catalog_name",
+ )
+ }
+ Statement::ShowDatabases { .. } | Statement::ShowSchemas { .. } => {
+ let catalog_name = match scope.as_deref() {
+ None => &config.default_catalog,
+ Some([catalog]) => catalog,
+ _ => {
+ return Err(DataFusionError::Plan(
+ "SHOW DATABASES IN requires one catalog name".into(),
+ ))
+ }
+ };
+ let names = if let Some(catalog) = catalogs.get(catalog_name) {
+ catalog
+ .list_databases()
+ .await
+ .map_err(crate::to_datafusion_error)?
+ } else {
+ ctx.catalog(catalog_name)
+ .ok_or_else(|| {
+ DataFusionError::Plan(format!("Unknown catalog
'{catalog_name}'"))
+ })?
+ .schema_names()
+ };
+ filter(
+ names_frame(ctx, "database_name", names)?,
+ options,
+ "database_name",
+ )
+ }
+ Statement::ShowTables { .. } => {
+ // Preserve unqualified SHOW TABLES across all catalogs. Scoped or
filtered
+ // listings default to the current catalog/database.
+ let frame = if scope.is_some() ||
options.filter_position.is_some() {
+ let (catalog_name, database_name) = match scope.as_deref() {
+ None => (&config.default_catalog, &config.default_schema),
+ Some([database]) => (&config.default_catalog, database),
+ Some([catalog, database]) => (catalog, database),
+ _ => {
+ return Err(DataFusionError::Plan(
+ "SHOW TABLES IN requires database or
catalog.database".into(),
+ ))
+ }
+ };
+ scoped_tables_frame(ctx, catalog_name, database_name).await?
+ } else {
+ ctx.table("information_schema.tables").await?
+ };
+ filter(frame, options, "table_name")?.sort(vec![
+ col("table_catalog").sort(true, true),
+ col("table_schema").sort(true, true),
+ col("table_name").sort(true, true),
+ ])
+ }
+ _ => unreachable!(),
+ }
+}
+
+async fn scoped_tables_frame(
+ ctx: &SessionContext,
+ catalog_name: &str,
+ database_name: &str,
+) -> Result<DataFrame> {
+ let catalog = ctx
+ .catalog(catalog_name)
+ .ok_or_else(|| DataFusionError::Plan(format!("Unknown catalog
'{catalog_name}'")))?;
+ let tables = if database_name == INFORMATION_SCHEMA &&
ctx.copied_config().information_schema()
+ {
+ INFORMATION_SCHEMA_TABLES
+ .iter()
+ .map(|name| (name.to_string(), TableType::View))
+ .collect()
+ } else if let Some(catalog) =
catalog.downcast_ref::<crate::catalog::PaimonCatalogProvider>() {
+ catalog.table_metadata(database_name).await?
+ } else {
+ let schema = catalog.schema(database_name).ok_or_else(|| {
+ DataFusionError::Plan(format!(
+ "Unknown namespace '{catalog_name}.{database_name}'"
+ ))
+ })?;
+ let mut tables = Vec::new();
+ for name in schema.table_names() {
+ if let Some(table_type) = schema.table_type(&name).await? {
+ tables.push((name, table_type));
+ }
+ }
+ tables
+ };
+ let schema = Arc::new(Schema::new(
+ ["table_catalog", "table_schema", "table_name", "table_type"]
+ .map(|name| Field::new(name, DataType::Utf8, false))
+ .to_vec(),
+ ));
+ let names = StringArray::from_iter_values(tables.iter().map(|(name, _)|
name));
+ let types =
+ StringArray::from_iter_values(tables.iter().map(|(_, table_type)|
match table_type {
+ TableType::Base => "BASE TABLE",
+ TableType::View => "VIEW",
+ TableType::Temporary => "LOCAL TEMPORARY",
+ }));
+ ctx.read_batch(RecordBatch::try_new(
+ schema,
+ vec![
+ Arc::new(StringArray::from(vec![catalog_name; tables.len()])),
+ Arc::new(StringArray::from(vec![database_name; tables.len()])),
+ Arc::new(names),
+ Arc::new(types),
+ ],
+ )?)
+}
+
+fn names_frame(ctx: &SessionContext, name: &str, mut values: Vec<String>) ->
Result<DataFrame> {
+ values.sort_unstable();
+ let schema = Arc::new(Schema::new(vec![Field::new(name, DataType::Utf8,
false)]));
+ ctx.read_batch(RecordBatch::try_new(
+ schema,
+ vec![Arc::new(StringArray::from(values))],
+ )?)
+}
+
+fn filter(frame: DataFrame, options: &ShowStatementOptions, name: &str) ->
Result<DataFrame> {
+ match options.filter_position.as_ref() {
+ None => Ok(frame),
+ Some(
+ ShowStatementFilterPosition::Infix(filter)
+ | ShowStatementFilterPosition::Suffix(filter),
+ ) => match filter {
+ ShowStatementFilter::Like(pattern) => {
+ frame.filter(col(name).like(lit(pattern.clone())))
+ }
+ ShowStatementFilter::ILike(pattern) => {
+ frame.filter(col(name).ilike(lit(pattern.clone())))
+ }
+ _ => Err(DataFusionError::Plan(
+ "SHOW supports only LIKE and ILIKE filters".into(),
+ )),
+ },
+ }
+}
diff --git a/crates/integrations/datafusion/src/sql_context.rs
b/crates/integrations/datafusion/src/sql_context.rs
index 6664835e..1432da55 100644
--- a/crates/integrations/datafusion/src/sql_context.rs
+++ b/crates/integrations/datafusion/src/sql_context.rs
@@ -485,24 +485,11 @@ impl SQLContext {
}
match &statements[0] {
- Statement::ShowDatabases {
- terse,
- history,
- show_options,
- } => {
- if *terse
- || *history
- || show_options.show_in.is_some()
- || show_options.starts_with.is_some()
- || show_options.limit.is_some()
- || show_options.limit_from.is_some()
- || show_options.filter_position.is_some()
- {
- return Err(DataFusionError::Plan(
- "SHOW DATABASES options are not supported".to_string(),
- ));
- }
- self.handle_show_databases().await
+ statement @ (Statement::ShowDatabases { .. }
+ | Statement::ShowSchemas { .. }
+ | Statement::ShowCatalogs { .. }
+ | Statement::ShowTables { .. }) => {
+ crate::show_metadata::execute(&self.ctx, &self.catalogs,
statement).await
}
Statement::CreateDatabase {
db_name,
@@ -1382,23 +1369,6 @@ impl SQLContext {
self.ctx.read_batch(batch)
}
- async fn handle_show_databases(&self) -> DFResult<DataFrame> {
- let catalog = self.current_catalog()?;
- let mut databases = catalog
- .list_databases()
- .await
- .map_err(to_datafusion_error)?;
- databases.sort_unstable();
-
- let schema = Arc::new(Schema::new(vec![Field::new(
- "database_name",
- ArrowDataType::Utf8,
- false,
- )]));
- let batch = RecordBatch::try_new(schema,
vec![Arc::new(StringArray::from(databases))])?;
- self.ctx.read_batch(batch)
- }
-
async fn handle_create_database(
&self,
name: &ObjectName,
diff --git a/crates/integrations/datafusion/tests/sql_context_tests.rs
b/crates/integrations/datafusion/tests/sql_context_tests.rs
index 325048a0..8ff8fed6 100644
--- a/crates/integrations/datafusion/tests/sql_context_tests.rs
+++ b/crates/integrations/datafusion/tests/sql_context_tests.rs
@@ -53,12 +53,20 @@ async fn create_sql_context(catalog:
Arc<FileSystemCatalog>) -> SQLContext {
struct MetadataListingCatalog {
get_table_calls: AtomicUsize,
+ deny_database_listing: AtomicBool,
+ deny_database_access: AtomicBool,
+ deny_table_listing: AtomicBool,
+ deny_view_listing: AtomicBool,
}
impl MetadataListingCatalog {
fn new() -> Self {
Self {
get_table_calls: AtomicUsize::new(0),
+ deny_database_listing: AtomicBool::new(false),
+ deny_database_access: AtomicBool::new(false),
+ deny_table_listing: AtomicBool::new(false),
+ deny_view_listing: AtomicBool::new(false),
}
}
@@ -70,6 +78,12 @@ impl MetadataListingCatalog {
#[async_trait]
impl Catalog for MetadataListingCatalog {
async fn list_databases(&self) -> paimon::Result<Vec<String>> {
+ if self.deny_database_listing.load(Ordering::SeqCst) {
+ return Err(paimon::Error::UnexpectedError {
+ message: "Forbidden: list databases".into(),
+ source: None,
+ });
+ }
Ok(vec!["default".to_string()])
}
@@ -83,6 +97,12 @@ impl Catalog for MetadataListingCatalog {
}
async fn get_database(&self, name: &str) ->
paimon::Result<paimon::catalog::Database> {
+ if self.deny_database_access.load(Ordering::SeqCst) {
+ return Err(paimon::Error::UnexpectedError {
+ message: "Forbidden: get database".into(),
+ source: None,
+ });
+ }
Ok(paimon::catalog::Database::new(
name.to_string(),
std::collections::HashMap::new(),
@@ -107,10 +127,22 @@ impl Catalog for MetadataListingCatalog {
}
async fn list_tables(&self, _database_name: &str) ->
paimon::Result<Vec<String>> {
+ if self.deny_table_listing.load(Ordering::SeqCst) {
+ return Err(paimon::Error::UnexpectedError {
+ message: "Forbidden: list tables".into(),
+ source: None,
+ });
+ }
Ok(vec!["metadata_only".to_string()])
}
async fn list_views(&self, _database_name: &str) ->
paimon::Result<Vec<String>> {
+ if self.deny_view_listing.load(Ordering::SeqCst) {
+ return Err(paimon::Error::UnexpectedError {
+ message: "Forbidden: list views".into(),
+ source: None,
+ });
+ }
Ok(vec!["metadata_view".to_string()])
}
@@ -834,6 +866,206 @@ async fn
test_branch_partitions_system_table_reads_branch_snapshot() {
// ======================= DATABASE / SCHEMA =======================
+#[tokio::test]
+async fn test_show_metadata_scopes_and_patterns() {
+ let (_tmp, catalog) = create_test_env();
+ let (_other_tmp, other_catalog) = create_test_env();
+ let mut ctx = create_sql_context(catalog).await;
+ ctx.register_catalog("other", other_catalog).await.unwrap();
+ for sql in [
+ "CREATE DATABASE analytics",
+ "CREATE DATABASE other.analytics",
+ "CREATE TABLE analytics.events_a (id INT)",
+ "CREATE TABLE analytics.events_b (id INT)",
+ "CREATE TABLE analytics.metrics (id INT)",
+ "CREATE TABLE other.analytics.events_other (id INT)",
+ "CREATE DATABASE \"Mixed.Db\"",
+ "CREATE TABLE \"Mixed.Db\".\"O'Reilly\" (id INT)",
+ ] {
+ ctx.sql(sql).await.unwrap();
+ }
+ for (sql, column, expected) in [
+ ("SHOW CATALOGS LIKE 'paim%'", "catalog_name", vec!["paimon"]),
+ (
+ "SHOW DATABASES LIKE 'ana%'",
+ "database_name",
+ vec!["analytics"],
+ ),
+ (
+ "SHOW SCHEMAS IN paimon LIKE 'ana%'",
+ "database_name",
+ vec!["analytics"],
+ ),
+ (
+ "SHOW TABLES IN analytics LIKE 'events_%'",
+ "table_name",
+ vec!["events_a", "events_b"],
+ ),
+ (
+ "SHOW TABLES FROM other.analytics",
+ "table_name",
+ vec!["events_other"],
+ ),
+ (
+ "SHOW TABLES IN analytics ILIKE 'EVENTS_%'",
+ "table_name",
+ vec!["events_a", "events_b"],
+ ),
+ (
+ "SHOW TABLES IN \"Mixed.Db\" LIKE 'O''Reilly'",
+ "table_name",
+ vec!["O'Reilly"],
+ ),
+ (
+ "SHOW TABLES IN analytics LIKE 'absent%'",
+ "table_name",
+ vec![],
+ ),
+ ] {
+ assert_eq!(
+ collect_string_column(&ctx, sql, column).await,
+ expected,
+ "{sql}"
+ );
+ }
+ ctx.sql("USE analytics").await.unwrap();
+ assert_eq!(
+ collect_string_column(&ctx, "SHOW TABLES LIKE 'events_%'",
"table_name").await,
+ vec!["events_a", "events_b"]
+ );
+}
+
+#[tokio::test]
+async fn test_show_tables_keeps_metadata_only_listing() {
+ let catalog = Arc::new(MetadataListingCatalog::new());
+ let mut ctx = SQLContext::new();
+ ctx.register_catalog("paimon", catalog.clone())
+ .await
+ .unwrap();
+ assert_eq!(
+ collect_string_column(
+ &ctx,
+ "SHOW TABLES IN default LIKE 'metadata_%'",
+ "table_name"
+ )
+ .await,
+ vec!["metadata_only", "metadata_view"]
+ );
+ assert_eq!(catalog.get_table_calls(), 0);
+}
+
+#[tokio::test]
+async fn
test_scoped_show_propagates_listing_denials_without_enumerating_databases() {
+ let catalog = Arc::new(MetadataListingCatalog::new());
+ let mut ctx = SQLContext::new();
+ ctx.register_catalog("paimon", catalog.clone())
+ .await
+ .unwrap();
+ for denied in [&catalog.deny_table_listing, &catalog.deny_view_listing] {
+ denied.store(true, Ordering::SeqCst);
+ let result = ctx.sql("SHOW TABLES IN default").await;
+ let error = match result {
+ Err(error) => error,
+ Ok(frame) => frame.collect().await.unwrap_err(),
+ };
+ assert!(error.to_string().contains("Forbidden: list"), "{error}");
+ denied.store(false, Ordering::SeqCst);
+ }
+ catalog.deny_database_listing.store(true, Ordering::SeqCst);
+ assert_eq!(
+ collect_string_column(&ctx, "SHOW TABLES IN default",
"table_name").await,
+ vec!["metadata_only", "metadata_view"]
+ );
+ assert_eq!(catalog.get_table_calls(), 0);
+ let schema = Arc::new(datafusion::arrow::datatypes::Schema::empty());
+ ctx.register_temp_table(
+ "default.visible_temp",
+ Arc::new(MemTable::try_new(schema, vec![vec![]]).unwrap()),
+ )
+ .unwrap();
+ catalog.deny_database_access.store(true, Ordering::SeqCst);
+ let result = ctx.sql("SHOW TABLES IN default").await;
+ let error = match result {
+ Err(error) => error,
+ Ok(frame) => frame.collect().await.unwrap_err(),
+ };
+ assert!(
+ error.to_string().contains("Forbidden: get database"),
+ "{error}"
+ );
+}
+
+#[tokio::test]
+async fn test_scoped_show_accepts_temp_only_database_and_shadowing() {
+ let (_tmp, catalog) = create_test_env();
+ let ctx = create_sql_context(catalog).await;
+ let schema = Arc::new(datafusion::arrow::datatypes::Schema::empty());
+ ctx.register_temp_table(
+ "scratch.temp_table",
+ Arc::new(MemTable::try_new(schema, vec![vec![]]).unwrap()),
+ )
+ .unwrap();
+ ctx.sql("CREATE TEMPORARY VIEW scratch.temp_view AS SELECT 1 AS id")
+ .await
+ .unwrap();
+ ctx.sql("SELECT * FROM scratch.temp_view")
+ .await
+ .unwrap()
+ .collect()
+ .await
+ .unwrap();
+ assert_eq!(
+ collect_string_column(&ctx, "SHOW TABLES IN scratch",
"table_name").await,
+ vec!["temp_table", "temp_view"]
+ );
+ ctx.sql("CREATE TABLE shadow (id INT)").await.unwrap();
+ ctx.sql("CREATE TEMPORARY VIEW shadow AS SELECT 1 AS id")
+ .await
+ .unwrap();
+ assert_eq!(
+ collect_string_column(&ctx, "SHOW TABLES IN default LIKE 'shadow'",
"table_type").await,
+ vec!["VIEW"]
+ );
+}
+
+#[tokio::test]
+async fn test_scoped_show_accepts_information_schema() {
+ let (_tmp, catalog) = create_test_env();
+ let ctx = create_sql_context(catalog).await;
+ assert_eq!(
+ collect_string_column(
+ &ctx,
+ "SHOW TABLES IN information_schema LIKE 'tables'",
+ "table_name"
+ )
+ .await,
+ vec!["tables"]
+ );
+ ctx.sql("SET datafusion.catalog.default_schema = 'information_schema'")
+ .await
+ .unwrap();
+ assert_eq!(
+ collect_string_column(&ctx, "SHOW TABLES LIKE 'columns'",
"table_name").await,
+ vec!["columns"]
+ );
+}
+
+#[tokio::test]
+async fn test_show_metadata_rejects_invalid_scope_and_unsupported_modifiers() {
+ let (_tmp, catalog) = create_test_env();
+ let ctx = create_sql_context(catalog).await;
+ for sql in [
+ "SHOW TABLES IN missing_catalog.default",
+ "SHOW TABLES IN missing_database",
+ "SHOW TABLES IN a.b.c",
+ "SHOW FULL TABLES IN default",
+ "SHOW TABLES IN default LIMIT 1",
+ "SHOW TABLES IN default WHERE table_name = 'x'",
+ ] {
+ assert!(ctx.sql(sql).await.is_err(), "accepted {sql}");
+ }
+}
+
#[tokio::test]
async fn test_database_statements() {
let (_tmp, catalog) = create_test_env();
@@ -875,7 +1107,7 @@ async fn
test_database_statements_reject_unsupported_options() {
assert_sql_error_contains(
&sql_context,
- "SHOW DATABASES LIKE 'a%'",
+ "SHOW DATABASES LIMIT 1",
"SHOW DATABASES options are not supported",
)
.await;
diff --git a/docs/src/sql.md b/docs/src/sql.md
index 6e10354a..956bcd30 100644
--- a/docs/src/sql.md
+++ b/docs/src/sql.md
@@ -597,6 +597,33 @@ DROP DATABASE paimon.my_db CASCADE;
`IF EXISTS` and `CASCADE`. `CREATE SCHEMA` and `DROP SCHEMA` remain supported
as compatibility aliases.
+### Metadata Listings
+
+```sql
+SHOW CATALOGS;
+SHOW CATALOGS LIKE 'paim%';
+SHOW DATABASES LIKE 'report%';
+SHOW SCHEMAS IN paimon LIKE 'report%';
+SHOW TABLES IN reporting;
+SHOW TABLES FROM paimon.reporting LIKE 'daily_%';
+```
+
+`SHOW SCHEMAS` is an alias for `SHOW DATABASES`; both return `database_name`.
+`SHOW CATALOGS` returns `catalog_name`. Database listings default to the
current
+catalog and accept `IN catalog` or `FROM catalog`.
+
+Table listings retain the `information_schema.tables` output columns.
+Unqualified `SHOW TABLES` retains DataFusion's listing across catalogs. A scope
+or filter restricts the listing to the current catalog/database unless an
+explicit database or `catalog.database` is supplied. Identifiers follow the
+session's normal quoting and case rules. `LIKE` uses SQL `%` and `_` wildcards;
+`ILIKE` ignores case. Table providers and data files are not loaded for
listing.
+Scoped and filtered table listings access only the selected namespace and
+propagate its metadata-listing errors. Session-only temporary namespaces and
+the enabled `information_schema` namespace are included.
+`FULL`, `EXTENDED`, `HISTORY`, `LIMIT`, `STARTS WITH`, typed scopes, and
`WHERE`
+filters are rejected rather than silently ignored.
+
### CREATE TABLE
```sql