You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/12/13 18:54:04 UTC

[GitHub] [arrow-datafusion] tustvold commented on a diff in pull request #4606: Lazy system tables

tustvold commented on code in PR #4606:
URL: https://github.com/apache/arrow-datafusion/pull/4606#discussion_r1047605470


##########
datafusion/core/src/catalog/information_schema.rs:
##########
@@ -220,74 +217,113 @@ impl InformationSchemaProvider {
                 }
             }
         }
-
-        let mem_table: MemTable = builder.into();
-
-        Arc::new(mem_table)
     }
 
     /// Construct the `information_schema.df_settings` virtual table
-    fn make_df_settings(&self) -> Arc<dyn TableProvider> {
-        let mut builder = InformationSchemaDfSettingsBuilder::new();
-
+    fn make_df_settings(&self, builder: &mut InformationSchemaDfSettingsBuilder) {
         for (name, setting) in self.config_options.read().options() {
             builder.add_setting(name, setting.to_string());
         }
-
-        let mem_table: MemTable = builder.into();
-
-        Arc::new(mem_table)
     }
 }
 
 impl SchemaProvider for InformationSchemaProvider {
-    fn as_any(&self) -> &(dyn any::Any + 'static) {
+    fn as_any(&self) -> &(dyn Any + 'static) {
         self
     }
 
     fn table_names(&self) -> Vec<String> {
-        vec![TABLES.to_string(), VIEWS.to_string(), COLUMNS.to_string()]
+        vec![
+            TABLES.to_string(),
+            VIEWS.to_string(),
+            COLUMNS.to_string(),
+            DF_SETTINGS.to_string(),
+        ]
     }
 
     fn table(&self, name: &str) -> Option<Arc<dyn TableProvider>> {
-        if name.eq_ignore_ascii_case("tables") {
-            Some(self.make_tables())
+        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") {
-            Some(self.make_columns())
+            Arc::new(InformationSchemaColumns::new(config))
         } else if name.eq_ignore_ascii_case("views") {
-            Some(self.make_views())
+            Arc::new(InformationSchemaViews::new(config))
         } else if name.eq_ignore_ascii_case("df_settings") {
-            Some(self.make_df_settings())
+            Arc::new(InformationSchemaDfSettings::new(config))
         } else {
-            None
-        }
+            return None;
+        };
+
+        Some(Arc::new(
+            StreamingTable::try_new(table.schema().clone(), vec![table]).unwrap(),
+        ))
     }
 
     fn table_exist(&self, name: &str) -> bool {
         matches!(name.to_ascii_lowercase().as_str(), TABLES | VIEWS | COLUMNS)
     }
 }
 
+struct InformationSchemaTables {
+    schema: SchemaRef,
+    config: InformationSchemaConfig,
+}
+
+impl InformationSchemaTables {
+    fn new(config: InformationSchemaConfig) -> Self {
+        let schema = Arc::new(Schema::new(vec![
+            Field::new("table_catalog", DataType::Utf8, false),
+            Field::new("table_schema", DataType::Utf8, false),
+            Field::new("table_name", DataType::Utf8, false),
+            Field::new("table_type", DataType::Utf8, false),
+        ]));
+
+        Self { schema, config }
+    }
+
+    fn builder(&self) -> InformationSchemaTablesBuilder {
+        InformationSchemaTablesBuilder {
+            catalog_names: StringBuilder::new(),
+            schema_names: StringBuilder::new(),
+            table_names: StringBuilder::new(),
+            table_types: StringBuilder::new(),
+            schema: self.schema.clone(),
+        }
+    }
+}
+
+impl PartitionStream for InformationSchemaTables {

Review Comment:
   This is significantly less verbose than having to define a `TableProvider` and then a corresponding `ExecutionPlan`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org