This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 801dc171be Simplify making information_schame tables (#10420)
801dc171be is described below

commit 801dc171bea7c02681640fdc65a5dfc995f01723
Author: 张林伟 <[email protected]>
AuthorDate: Thu May 9 01:57:50 2024 +0800

    Simplify making information_schame tables (#10420)
    
    * Simplify making information_schame tables
    
    * Simplify InformationSchemaProvider
    
    * Remove lifetime annotation
    
    * Replace if with match
    
    * case insensitive
    
    * Add test
---
 datafusion/core/src/catalog/information_schema.rs  | 65 +++++++---------------
 .../sqllogictest/test_files/information_schema.slt |  6 ++
 2 files changed, 27 insertions(+), 44 deletions(-)

diff --git a/datafusion/core/src/catalog/information_schema.rs 
b/datafusion/core/src/catalog/information_schema.rs
index cd8f764953..a9d4590a5e 100644
--- a/datafusion/core/src/catalog/information_schema.rs
+++ b/datafusion/core/src/catalog/information_schema.rs
@@ -107,26 +107,14 @@ impl InformationSchemaConfig {
             }
 
             // Add a final list for the information schema tables themselves
-            builder.add_table(&catalog_name, INFORMATION_SCHEMA, TABLES, 
TableType::View);
-            builder.add_table(&catalog_name, INFORMATION_SCHEMA, VIEWS, 
TableType::View);
-            builder.add_table(
-                &catalog_name,
-                INFORMATION_SCHEMA,
-                COLUMNS,
-                TableType::View,
-            );
-            builder.add_table(
-                &catalog_name,
-                INFORMATION_SCHEMA,
-                DF_SETTINGS,
-                TableType::View,
-            );
-            builder.add_table(
-                &catalog_name,
-                INFORMATION_SCHEMA,
-                SCHEMATA,
-                TableType::View,
-            );
+            for table_name in INFORMATION_SCHEMA_TABLES {
+                builder.add_table(
+                    &catalog_name,
+                    INFORMATION_SCHEMA,
+                    table_name,
+                    TableType::View,
+                );
+            }
         }
 
         Ok(())
@@ -225,18 +213,15 @@ impl InformationSchemaConfig {
 
 #[async_trait]
 impl SchemaProvider for InformationSchemaProvider {
-    fn as_any(&self) -> &(dyn Any + 'static) {
+    fn as_any(&self) -> &dyn Any {
         self
     }
 
     fn table_names(&self) -> Vec<String> {
-        vec![
-            TABLES.to_string(),
-            VIEWS.to_string(),
-            COLUMNS.to_string(),
-            DF_SETTINGS.to_string(),
-            SCHEMATA.to_string(),
-        ]
+        INFORMATION_SCHEMA_TABLES
+            .iter()
+            .map(|t| t.to_string())
+            .collect()
     }
 
     async fn table(
@@ -244,18 +229,13 @@ impl SchemaProvider for InformationSchemaProvider {
         name: &str,
     ) -> Result<Option<Arc<dyn TableProvider>>, DataFusionError> {
         let config = self.config.clone();
-        let table: Arc<dyn PartitionStream> = if 
name.eq_ignore_ascii_case("tables") {
-            Arc::new(InformationSchemaTables::new(config))
-        } else if name.eq_ignore_ascii_case("columns") {
-            Arc::new(InformationSchemaColumns::new(config))
-        } else if name.eq_ignore_ascii_case("views") {
-            Arc::new(InformationSchemaViews::new(config))
-        } else if name.eq_ignore_ascii_case("df_settings") {
-            Arc::new(InformationSchemaDfSettings::new(config))
-        } else if name.eq_ignore_ascii_case("schemata") {
-            Arc::new(InformationSchemata::new(config))
-        } else {
-            return Ok(None);
+        let table: Arc<dyn PartitionStream> = match 
name.to_ascii_lowercase().as_str() {
+            TABLES => Arc::new(InformationSchemaTables::new(config)),
+            COLUMNS => Arc::new(InformationSchemaColumns::new(config)),
+            VIEWS => Arc::new(InformationSchemaViews::new(config)),
+            DF_SETTINGS => Arc::new(InformationSchemaDfSettings::new(config)),
+            SCHEMATA => Arc::new(InformationSchemata::new(config)),
+            _ => return Ok(None),
         };
 
         Ok(Some(Arc::new(
@@ -264,10 +244,7 @@ impl SchemaProvider for InformationSchemaProvider {
     }
 
     fn table_exist(&self, name: &str) -> bool {
-        matches!(
-            name.to_ascii_lowercase().as_str(),
-            TABLES | VIEWS | COLUMNS | SCHEMATA
-        )
+        INFORMATION_SCHEMA_TABLES.contains(&name.to_ascii_lowercase().as_str())
     }
 }
 
diff --git a/datafusion/sqllogictest/test_files/information_schema.slt 
b/datafusion/sqllogictest/test_files/information_schema.slt
index f54ded975f..f52147142c 100644
--- a/datafusion/sqllogictest/test_files/information_schema.slt
+++ b/datafusion/sqllogictest/test_files/information_schema.slt
@@ -49,6 +49,12 @@ SELECT * from information_schema.schemata;
 ----
 datafusion public NULL NULL NULL NULL NULL
 
+# Table name case insensitive
+query T rowsort
+SELECT catalog_name from information_schema.SchEmaTa;
+----
+datafusion
+
 # Disable information_schema and verify it now errors again
 statement ok
 set datafusion.catalog.information_schema = false


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to