alamb commented on code in PR #26057:
URL: https://github.com/apache/datafusion/pull/26057#discussion_r4393817152


##########
datafusion/common/src/information_schema.rs:
##########
@@ -0,0 +1,1046 @@
+// 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.
+
+//! Schema and [`RecordBatch`] builders for the `information_schema` virtual
+//! tables and `SHOW` statements.
+
+use crate::Result;
+use crate::TableType;
+use crate::config::ConfigEntry;
+use arrow::array::ArrayRef;
+use arrow::array::builder::{BooleanBuilder, StringBuilder, UInt8Builder, 
UInt64Builder};
+use arrow::datatypes::{DataType, Field, Schema, SchemaRef};
+use arrow::record_batch::RecordBatch;
+use std::sync::Arc;
+
+/// Returns the Arrow schema of `information_schema.tables` rows.
+///
+/// Columns are based on 
<https://www.postgresql.org/docs/current/infoschema-tables.html>.
+pub fn tables_schema() -> Schema {
+    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),
+    ])
+}
+
+/// Builds `information_schema.tables` rows.
+#[derive(Debug)]
+pub struct InformationSchemaTablesBuilder {
+    schema: SchemaRef,
+    catalog_names: StringBuilder,
+    schema_names: StringBuilder,
+    table_names: StringBuilder,
+    table_types: StringBuilder,
+}
+
+impl Default for InformationSchemaTablesBuilder {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
+impl InformationSchemaTablesBuilder {
+    /// Construct an empty builder.
+    pub fn new() -> Self {
+        Self {
+            schema: Arc::new(tables_schema()),
+            catalog_names: StringBuilder::new(),
+            schema_names: StringBuilder::new(),
+            table_names: StringBuilder::new(),
+            table_types: StringBuilder::new(),
+        }
+    }
+
+    /// Append one row.
+    pub fn add_table(
+        &mut self,
+        catalog_name: impl AsRef<str>,
+        schema_name: impl AsRef<str>,
+        table_name: impl AsRef<str>,
+        table_type: TableType,
+    ) {
+        // Note: append_value is actually infallible.
+        self.catalog_names.append_value(catalog_name.as_ref());
+        self.schema_names.append_value(schema_name.as_ref());
+        self.table_names.append_value(table_name.as_ref());
+        self.table_types.append_value(match table_type {
+            TableType::Base => "BASE TABLE",
+            TableType::View => "VIEW",
+            TableType::Temporary => "LOCAL TEMPORARY",
+        });
+    }
+
+    /// Finalize the builder into a [`RecordBatch`].
+    pub fn finish(&mut self) -> RecordBatch {
+        RecordBatch::try_new(
+            Arc::clone(&self.schema),
+            vec![
+                Arc::new(self.catalog_names.finish()),
+                Arc::new(self.schema_names.finish()),
+                Arc::new(self.table_names.finish()),
+                Arc::new(self.table_types.finish()),
+            ],
+        )
+        .unwrap()
+    }
+}
+
+/// Returns the Arrow schema of `information_schema.views` rows.
+///
+/// Columns are based on 
<https://www.postgresql.org/docs/current/infoschema-views.html>.
+pub fn views_schema() -> Schema {
+    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("definition", DataType::Utf8, true),
+    ])
+}
+
+/// Builds `information_schema.views` rows.
+#[derive(Debug)]
+pub struct InformationSchemaViewBuilder {

Review Comment:
   it took me a while to understand why this stuff was moved to common, and 
then I realized it is because the LogicalPlan now depends on the information 
schema to report its schema 🤔 



##########
datafusion/catalog/src/information_schema.rs:
##########
@@ -22,34 +22,52 @@
 use crate::streaming::StreamingTable;
 use crate::table::TableFunction;
 use crate::{CatalogProviderList, SchemaProvider, TableProvider};
-use arrow::array::builder::{BooleanBuilder, UInt8Builder};
-use arrow::{
-    array::{StringBuilder, UInt64Builder},
-    datatypes::{DataType, Field, FieldRef, Schema, SchemaRef},
-    record_batch::RecordBatch,
-};
+use arrow::array::StringArray;
+use arrow::array::builder::{ListBuilder, StringBuilder};
+use arrow::compute::kernels::filter::filter_record_batch;
+use arrow::compute::like;
+use arrow::datatypes::{DataType, Field, FieldRef, Schema, SchemaRef};
+use arrow::record_batch::RecordBatch;
 use async_trait::async_trait;
-use datafusion_common::DataFusionError;
-use datafusion_common::config::{ConfigEntry, ConfigOptions};
+use datafusion_common::config::ConfigOptions;
 use datafusion_common::error::Result;
+use datafusion_common::information_schema::{
+    ColumnsDetail, InformationSchemaColumnsBuilder, 
InformationSchemaDfSettingsBuilder,
+    InformationSchemaParametersBuilder, InformationSchemaRoutinesBuilder,
+    InformationSchemaTablesBuilder, InformationSchemaViewBuilder, 
columns_schema,
+    df_settings_schema, parameters_schema, routines_schema, 
show_functions_schema,
+    tables_schema, views_schema,
+};
+use datafusion_common::{
+    DataFusionError, ResolvedTableReference, plan_datafusion_err, plan_err,
+};
+// Re-exported (rather than just `use`d) because these were already part of
+// this module's public API before it started sharing its schema/builder
+// definitions with `datafusion_common::information_schema`.
+pub use datafusion_common::information_schema::{
+    InformationSchemataBuilder, schemata_schema,
+};
 use datafusion_common::types::{LogicalType, NativeType};
+use datafusion_datasource::memory::MemorySourceConfig;
 use datafusion_execution::TaskContext;
 use datafusion_execution::runtime_env::RuntimeEnv;
 use datafusion_expr::function::WindowUDFFieldArgs;
 use datafusion_expr::type_coercion::functions::fields_with_udf;
 use datafusion_expr::{
-    AggregateUDF, ReturnFieldArgs, ScalarUDF, Signature, TypeSignature, 
WindowUDF,
+    AggregateUDF, Documentation, ReturnFieldArgs, ScalarUDF, Signature, 
TypeSignature,
+    WindowUDF,
 };
 use datafusion_expr::{TableType, Volatility};
-use datafusion_physical_plan::SendableRecordBatchStream;
 use datafusion_physical_plan::stream::RecordBatchStreamAdapter;
-use datafusion_physical_plan::streaming::PartitionStream;
+use datafusion_physical_plan::streaming::{PartitionStream, StreamingTableExec};
+use datafusion_physical_plan::{ExecutionPlan, SendableRecordBatchStream};
 use datafusion_session::CatalogProvider;
 use itertools::Itertools;
 use std::collections::{BTreeSet, HashMap, HashSet};
 use std::fmt::Debug;
 use std::sync::Arc;
 
+/// Name of the `information_schema` schema

Review Comment:
   I like how much simpler this code is



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to