Apache DataFusion SQL Query Engine
Derive `Debug` for `SessionStateBuilder`, adding `Debug` requirements to fields (#12632)
AnthonyZhOon4df83f5af421
diff --git a/datafusion-cli/src/catalog.rs b/datafusion-cli/src/catalog.rsindex 9b9afc1c24..ceb72dbc54 100644--- a/datafusion-cli/src/catalog.rs+++ b/datafusion-cli/src/catalog.rs@@ -34,6 +34,7 @@ use dirs::home_dir;use parking_lot::RwLock;/// Wraps another catalog, automatically register require object stores for the file locations+#[derive(Debug)]pub struct DynamicObjectStoreCatalog {inner: Arc<dyn CatalogProviderList>,state: Weak<RwLock<SessionState>>,@@ -74,6 +75,7 @@ impl CatalogProviderList for DynamicObjectStoreCatalog {}/// Wraps another catalog provider+#[derive(Debug)]struct DynamicObjectStoreCatalogProvider {inner: Arc<dyn CatalogProvider>,state: Weak<RwLock<SessionState>>,@@ -115,6 +117,7 @@ impl CatalogProvider for DynamicObjectStoreCatalogProvider {/// Wraps another schema provider. [DynamicObjectStoreSchemaProvider] is responsible for registering the required/// object stores for the file locations.+#[derive(Debug)]struct DynamicObjectStoreSchemaProvider {inner: Arc<dyn SchemaProvider>,state: Weak<RwLock<SessionState>>,diff --git a/datafusion-cli/src/functions.rs b/datafusion-cli/src/functions.rsindex dd56b0196d..c622463de0 100644--- a/datafusion-cli/src/functions.rs+++ b/datafusion-cli/src/functions.rs@@ -315,6 +315,7 @@ fn fixed_len_byte_array_to_string(val: Option<&FixedLenByteArray>) -> Option<Str})}+#[derive(Debug)]pub struct ParquetMetadataFunc {}impl TableFunctionImpl for ParquetMetadataFunc {diff --git a/datafusion-examples/examples/catalog.rs b/datafusion-examples/examples/catalog.rsindex 8c2b1aad56..f40f1dfb5a 100644--- a/datafusion-examples/examples/catalog.rs+++ b/datafusion-examples/examples/catalog.rs@@ -135,6 +135,7 @@ struct DirSchemaOpts<'a> {format: Arc<dyn FileFormat>,}/// Schema where every file with extension `ext` in a given `dir` is a table.+#[derive(Debug)]struct DirSchema {ext: String,tables: RwLock<HashMap<String, Arc<dyn TableProvider>>>,@@ -218,6 +219,7 @@ impl SchemaProvider for DirSchema {}}/// Catalog holds multiple schemas+#[derive(Debug)]struct DirCatalog {schemas: RwLock<HashMap<String, Arc<dyn SchemaProvider>>>,}@@ -259,6 +261,7 @@ impl CatalogProvider for DirCatalog {}}/// Catalog lists holds multiple catalog providers. Each context has a single catalog list.+#[derive(Debug)]struct CustomCatalogProviderList {catalogs: RwLock<HashMap<String, Arc<dyn CatalogProvider>>>,}diff --git a/datafusion-examples/examples/simple_udtf.rs b/datafusion-examples/examples/simple_udtf.rsindex baa783fce9..6faa397ef6 100644--- a/datafusion-examples/examples/simple_udtf.rs+++ b/datafusion-examples/examples/simple_udtf.rs@@ -128,6 +128,7 @@ impl TableProvider for LocalCsvTable {}}+#[derive(Debug)]struct LocalCsvTableFunc {}impl TableFunctionImpl for LocalCsvTableFunc {diff --git a/datafusion/catalog/src/catalog.rs b/datafusion/catalog/src/catalog.rsindex 9ee94e8f1f..048a7f14ed 100644--- a/datafusion/catalog/src/catalog.rs+++ b/datafusion/catalog/src/catalog.rs@@ -16,6 +16,7 @@// under the License.use std::any::Any;+use std::fmt::Debug;use std::sync::Arc;pub use crate::schema::SchemaProvider;@@ -101,7 +102,7 @@ use datafusion_common::Result;////// [`TableProvider`]: crate::TableProvider-pub trait CatalogProvider: Sync + Send {+pub trait CatalogProvider: Debug + Sync + Send {/// Returns the catalog provider as [`Any`]/// so that it can be downcast to a specific implementation.fn as_any(&self) -> &dyn Any;@@ -152,7 +153,7 @@ pub trait CatalogProvider: Sync + Send {////// Please see the documentation on `CatalogProvider` for details of/// implementing a custom catalog.-pub trait CatalogProviderList: Sync + Send {+pub trait CatalogProviderList: Debug + Sync + Send {/// Returns the catalog list as [`Any`]/// so that it can be downcast to a specific implementation.fn as_any(&self) -> &dyn Any;diff --git a/datafusion/catalog/src/dynamic_file/catalog.rs b/datafusion/catalog/src/dynamic_file/catalog.rsindex cd586446f8..ccccb9762e 100644--- a/datafusion/catalog/src/dynamic_file/catalog.rs+++ b/datafusion/catalog/src/dynamic_file/catalog.rs@@ -20,9 +20,11 @@use crate::{CatalogProvider, CatalogProviderList, SchemaProvider, TableProvider};use async_trait::async_trait;use std::any::Any;+use std::fmt::Debug;use std::sync::Arc;/// Wrap another catalog provider list+#[derive(Debug)]pub struct DynamicFileCatalog {/// The inner catalog provider listinner: Arc<dyn CatalogProviderList>,@@ -67,6 +69,7 @@ impl CatalogProviderList for DynamicFileCatalog {}/// Wraps another catalog provider+#[derive(Debug)]struct DynamicFileCatalogProvider {/// The inner catalog providerinner: Arc<dyn CatalogProvider>,@@ -114,6 +117,7 @@ impl CatalogProvider for DynamicFileCatalogProvider {////// The provider will try to create a table provider from the file path if the table provider/// isn't exist in the inner schema provider.+#[derive(Debug)]pub struct DynamicFileSchemaProvider {/// The inner schema providerinner: Arc<dyn SchemaProvider>,@@ -174,7 +178,7 @@ impl SchemaProvider for DynamicFileSchemaProvider {/// [UrlTableFactory] is a factory that can create a table provider from the given url.#[async_trait]-pub trait UrlTableFactory: Sync + Send {+pub trait UrlTableFactory: Debug + Sync + Send {/// create a new table provider from the provided urlasync fn try_new(&self,diff --git a/datafusion/catalog/src/schema.rs b/datafusion/catalog/src/schema.rsindex 21bca9fa82..5b37348fd7 100644--- a/datafusion/catalog/src/schema.rs+++ b/datafusion/catalog/src/schema.rs@@ -21,6 +21,7 @@use async_trait::async_trait;use datafusion_common::{exec_err, DataFusionError};use std::any::Any;+use std::fmt::Debug;use std::sync::Arc;use crate::table::TableProvider;@@ -32,7 +33,7 @@ use datafusion_common::Result;////// [`CatalogProvider`]: super::CatalogProvider#[async_trait]-pub trait SchemaProvider: Sync + Send {+pub trait SchemaProvider: Debug + Sync + Send {/// Returns the owner of the Schema, default is None. This value is reported/// as part of `information_tables.schematafn owner_name(&self) -> Option<&str> {diff --git a/datafusion/catalog/src/session.rs b/datafusion/catalog/src/session.rsindex 61d9c2d8a7..db49529ac4 100644--- a/datafusion/catalog/src/session.rs+++ b/datafusion/catalog/src/session.rs@@ -139,6 +139,7 @@ impl From<&dyn Session> for TaskContext {}type SessionRefLock = Arc<Mutex<Option<Weak<RwLock<dyn Session>>>>>;/// The state store that stores the reference of the runtime session state.+#[derive(Debug)]pub struct SessionStore {session: SessionRefLock,}diff --git a/datafusion/core/src/catalog_common/information_schema.rs b/datafusion/core/src/catalog_common/information_schema.rsindex df4257504b..180994b1cb 100644--- a/datafusion/core/src/catalog_common/information_schema.rs+++ b/datafusion/core/src/catalog_common/information_schema.rs@@ -26,7 +26,7 @@ use arrow::{};use async_trait::async_trait;use datafusion_common::DataFusionError;-use std::fmt::{Debug, Formatter};+use std::fmt::Debug;use std::{any::Any, sync::Arc};use crate::catalog::{CatalogProviderList, SchemaProvider, TableProvider};@@ -57,6 +57,7 @@ pub const INFORMATION_SCHEMA_TABLES: &[&str] =/// demand. This means that if more tables are added to the underlying/// providers, they will appear the next time the `information_schema`/// table is queried.+#[derive(Debug)]pub struct InformationSchemaProvider {config: InformationSchemaConfig,}@@ -70,20 +71,11 @@ impl InformationSchemaProvider {}}-#[derive(Clone)]+#[derive(Clone, Debug)]struct InformationSchemaConfig {catalog_list: Arc<dyn CatalogProviderList>,}-impl Debug for InformationSchemaConfig {- fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {- f.debug_struct("InformationSchemaConfig")- // TODO it would be great to print the catalog list here- // but that would require CatalogProviderList to implement Debug- .finish_non_exhaustive()- }-}-impl InformationSchemaConfig {/// Construct the `information_schema.tables` virtual tableasync fn make_tables(diff --git a/datafusion/core/src/catalog_common/listing_schema.rs b/datafusion/core/src/catalog_common/listing_schema.rsindex 5b91f963ca..e45c8a8d4a 100644--- a/datafusion/core/src/catalog_common/listing_schema.rs+++ b/datafusion/core/src/catalog_common/listing_schema.rs@@ -48,6 +48,7 @@ use object_store::ObjectStore;/// - `s3://host.example.com:3000/data/tpch/customer/_delta_log/`////// [`ObjectStore`]: object_store::ObjectStore+#[derive(Debug)]pub struct ListingSchemaProvider {authority: String,path: object_store::path::Path,diff --git a/datafusion/core/src/catalog_common/memory.rs b/datafusion/core/src/catalog_common/memory.rsindex 6d8bddec45..f251466168 100644--- a/datafusion/core/src/catalog_common/memory.rs+++ b/datafusion/core/src/catalog_common/memory.rs@@ -28,6 +28,7 @@ use std::any::Any;use std::sync::Arc;/// Simple in-memory list of catalogs+#[derive(Debug)]pub struct MemoryCatalogProviderList {/// Collection of catalogs containing schemas and ultimately TableProviderspub catalogs: DashMap<String, Arc<dyn CatalogProvider>>,@@ -71,6 +72,7 @@ impl CatalogProviderList for MemoryCatalogProviderList {}/// Simple in-memory implementation of a catalog.+#[derive(Debug)]pub struct MemoryCatalogProvider {schemas: DashMap<String, Arc<dyn SchemaProvider>>,}@@ -136,6 +138,7 @@ impl CatalogProvider for MemoryCatalogProvider {}/// Simple in-memory implementation of a schema.+#[derive(Debug)]pub struct MemorySchemaProvider {tables: DashMap<String, Arc<dyn TableProvider>>,}@@ -248,6 +251,7 @@ mod test {#[test]fn default_register_schema_not_supported() {// mimic a new CatalogProvider and ensure it does not support registering schemas+ #[derive(Debug)]struct TestProvider {}impl CatalogProvider for TestProvider {fn as_any(&self) -> &dyn Any {diff --git a/datafusion/core/src/datasource/dynamic_file.rs b/datafusion/core/src/datasource/dynamic_file.rsindex a95f3abb93..3c409af297 100644--- a/datafusion/core/src/datasource/dynamic_file.rs+++ b/datafusion/core/src/datasource/dynamic_file.rs@@ -30,7 +30,7 @@ use crate::error::Result;use crate::execution::context::SessionState;/// [DynamicListTableFactory] is a factory that can create a [ListingTable] from the given url.-#[derive(Default)]+#[derive(Default, Debug)]pub struct DynamicListTableFactory {/// The session store that contains the current session.session_store: SessionStore,diff --git a/datafusion/core/src/datasource/function.rs b/datafusion/core/src/datasource/function.rsindex 14bbc431f9..37ce59f820 100644--- a/datafusion/core/src/datasource/function.rs+++ b/datafusion/core/src/datasource/function.rs@@ -22,15 +22,17 @@ use super::TableProvider;use datafusion_common::Result;use datafusion_expr::Expr;+use std::fmt::Debug;use std::sync::Arc;/// A trait for table function implementations-pub trait TableFunctionImpl: Sync + Send {+pub trait TableFunctionImpl: Debug + Sync + Send {/// Create a table providerfn call(&self, args: &[Expr]) -> Result<Arc<dyn TableProvider>>;}/// A table that uses a function to generate data+#[derive(Debug)]pub struct TableFunction {/// Name of the table functionname: String,diff --git a/datafusion/core/src/execution/context/mod.rs b/datafusion/core/src/execution/context/mod.rsindex 12ce71768f..b0951d9ec4 100644--- a/datafusion/core/src/execution/context/mod.rs+++ b/datafusion/core/src/execution/context/mod.rs@@ -1547,7 +1547,7 @@ impl From<SessionContext> for SessionStateBuilder {/// A planner used to add extensions to DataFusion logical and physical plans.#[async_trait]-pub trait QueryPlanner {+pub trait QueryPlanner: Debug {/// Given a `LogicalPlan`, create an [`ExecutionPlan`] suitable for executionasync fn create_physical_plan(&self,@@ -1560,7 +1560,7 @@ pub trait QueryPlanner {/// and interact with [SessionState] to registers new udf, udaf or udwf.#[async_trait]-pub trait FunctionFactory: Sync + Send {+pub trait FunctionFactory: Debug + Sync + Send {/// Handles creation of user defined function specified in [CreateFunction] statementasync fn create(&self,@@ -1583,6 +1583,7 @@ pub enum RegisterFunction {/// Default implementation of [SerializerRegistry] that throws unimplemented error/// for all requests.+#[derive(Debug)]pub struct EmptySerializerRegistry;impl SerializerRegistry for EmptySerializerRegistry {@@ -2129,6 +2130,7 @@ mod tests {}}+ #[derive(Debug)]struct MyQueryPlanner {}#[async_trait]diff --git a/datafusion/core/src/execution/session_state.rs b/datafusion/core/src/execution/session_state.rsindex 3e6577a486..cffb63f520 100644--- a/datafusion/core/src/execution/session_state.rs+++ b/datafusion/core/src/execution/session_state.rs@@ -177,23 +177,23 @@ impl Debug for SessionState {fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {f.debug_struct("SessionState").field("session_id", &self.session_id)- .field("analyzer", &"...")+ .field("config", &self.config)+ .field("runtime_env", &self.runtime_env)+ .field("catalog_list", &"...")+ .field("serializer_registry", &"...")+ .field("execution_props", &self.execution_props)+ .field("table_options", &self.table_options)+ .field("table_factories", &"...")+ .field("function_factory", &"...").field("expr_planners", &"...")+ .field("query_planner", &"...")+ .field("analyzer", &"...").field("optimizer", &"...").field("physical_optimizers", &"...")- .field("query_planner", &"...")- .field("catalog_list", &"...").field("table_functions", &"...").field("scalar_functions", &self.scalar_functions).field("aggregate_functions", &self.aggregate_functions).field("window_functions", &self.window_functions)- .field("serializer_registry", &"...")- .field("config", &self.config)- .field("table_options", &self.table_options)- .field("execution_props", &self.execution_props)- .field("table_factories", &"...")- .field("runtime_env", &self.runtime_env)- .field("function_factory", &"...").finish_non_exhaustive()}}@@ -1519,6 +1519,37 @@ impl SessionStateBuilder {}}+impl Debug for SessionStateBuilder {+ /// Prefer having short fields at the top and long vector fields near the end+ /// Group fields by+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {+ f.debug_struct("SessionStateBuilder")+ .field("session_id", &self.session_id)+ .field("config", &self.config)+ .field("runtime_env", &self.runtime_env)+ .field("catalog_list", &self.catalog_list)+ .field("serializer_registry", &self.serializer_registry)+ .field("file_formats", &self.file_formats)+ .field("execution_props", &self.execution_props)+ .field("table_options", &self.table_options)+ .field("table_factories", &self.table_factories)+ .field("function_factory", &self.function_factory)+ .field("expr_planners", &self.expr_planners)+ .field("query_planners", &self.query_planner)+ .field("analyzer_rules", &self.analyzer_rules)+ .field("analyzer", &self.analyzer)+ .field("optimizer_rules", &self.optimizer_rules)+ .field("optimizer", &self.optimizer)+ .field("physical_optimizer_rules", &self.physical_optimizer_rules)+ .field("physical_optimizers", &self.physical_optimizers)+ .field("table_functions", &self.table_functions)+ .field("scalar_functions", &self.scalar_functions)+ .field("aggregate_functions", &self.aggregate_functions)+ .field("window_functions", &self.window_functions)+ .finish()+ }+}+impl Default for SessionStateBuilder {fn default() -> Self {Self::new()@@ -1795,6 +1826,7 @@ impl From<&SessionState> for TaskContext {}/// The query planner used if no user defined planner is provided+#[derive(Debug)]struct DefaultQueryPlanner {}#[async_trait]diff --git a/datafusion/core/tests/user_defined/expr_planner.rs b/datafusion/core/tests/user_defined/expr_planner.rsindex 1b23bf9ab2..ad9c1280d6 100644--- a/datafusion/core/tests/user_defined/expr_planner.rs+++ b/datafusion/core/tests/user_defined/expr_planner.rs@@ -29,6 +29,7 @@ use datafusion_expr::expr::Alias;use datafusion_expr::planner::{ExprPlanner, PlannerResult, RawBinaryExpr};use datafusion_expr::BinaryExpr;+#[derive(Debug)]struct MyCustomPlanner;impl ExprPlanner for MyCustomPlanner {diff --git a/datafusion/core/tests/user_defined/user_defined_plan.rs b/datafusion/core/tests/user_defined/user_defined_plan.rsindex caf639434a..e51adbc4dd 100644--- a/datafusion/core/tests/user_defined/user_defined_plan.rs+++ b/datafusion/core/tests/user_defined/user_defined_plan.rs@@ -312,6 +312,7 @@ fn make_topk_context() -> SessionContext {// ------ The implementation of the TopK code follows -----+#[derive(Debug)]struct TopKQueryPlanner {}#[async_trait]diff --git a/datafusion/core/tests/user_defined/user_defined_table_functions.rs b/datafusion/core/tests/user_defined/user_defined_table_functions.rsindex fe57752db5..0cc156866d 100644--- a/datafusion/core/tests/user_defined/user_defined_table_functions.rs+++ b/datafusion/core/tests/user_defined/user_defined_table_functions.rs@@ -192,6 +192,7 @@ impl SimpleCsvTable {}}+#[derive(Debug)]struct SimpleCsvTableFunc {}impl TableFunctionImpl for SimpleCsvTableFunc {diff --git a/datafusion/expr/src/planner.rs b/datafusion/expr/src/planner.rsindex 24f589c415..7dd7360e47 100644--- a/datafusion/expr/src/planner.rs+++ b/datafusion/expr/src/planner.rs@@ -17,6 +17,7 @@//! [`ContextProvider`] and [`ExprPlanner`] APIs to customize SQL query planning+use std::fmt::Debug;use std::sync::Arc;use arrow::datatypes::{DataType, Field, SchemaRef};@@ -88,7 +89,7 @@ pub trait ContextProvider {}/// This trait allows users to customize the behavior of the SQL planner-pub trait ExprPlanner: Send + Sync {+pub trait ExprPlanner: Debug + Send + Sync {/// Plan the binary operation between two expressions, returns original/// BinaryExpr if not possiblefn plan_binary_op(diff --git a/datafusion/expr/src/registry.rs b/datafusion/expr/src/registry.rsindex 988dc0f5ae..6d3457f70d 100644--- a/datafusion/expr/src/registry.rs+++ b/datafusion/expr/src/registry.rs@@ -21,8 +21,9 @@ use crate::expr_rewriter::FunctionRewrite;use crate::planner::ExprPlanner;use crate::{AggregateUDF, ScalarUDF, UserDefinedLogicalNode, WindowUDF};use datafusion_common::{not_impl_err, plan_datafusion_err, Result};-use std::collections::HashMap;-use std::{collections::HashSet, sync::Arc};+use std::collections::{HashMap, HashSet};+use std::fmt::Debug;+use std::sync::Arc;/// A registry knows how to build logical expressions out of user-defined function' namespub trait FunctionRegistry {@@ -123,7 +124,7 @@ pub trait FunctionRegistry {}/// Serializer and deserializer registry for extensions like [UserDefinedLogicalNode].-pub trait SerializerRegistry: Send + Sync {+pub trait SerializerRegistry: Debug + Send + Sync {/// Serialize this node to a byte array. This serialization should not include/// input plans.fn serialize_logical_plan(diff --git a/datafusion/functions-nested/src/planner.rs b/datafusion/functions-nested/src/planner.rsindex 4cd8faa3ca..9ae2fa781d 100644--- a/datafusion/functions-nested/src/planner.rs+++ b/datafusion/functions-nested/src/planner.rs@@ -34,6 +34,7 @@ use crate::{make_array::make_array,};+#[derive(Debug)]pub struct NestedFunctionPlanner;impl ExprPlanner for NestedFunctionPlanner {@@ -130,6 +131,7 @@ impl ExprPlanner for NestedFunctionPlanner {}}+#[derive(Debug)]pub struct FieldAccessPlanner;impl ExprPlanner for FieldAccessPlanner {diff --git a/datafusion/functions/src/core/planner.rs b/datafusion/functions/src/core/planner.rsindex 12fcb4a263..5873b4e1af 100644--- a/datafusion/functions/src/core/planner.rs+++ b/datafusion/functions/src/core/planner.rs@@ -24,7 +24,7 @@ use datafusion_expr::{lit, Expr};use super::named_struct;-#[derive(Default)]+#[derive(Default, Debug)]pub struct CoreFunctionPlanner {}impl ExprPlanner for CoreFunctionPlanner {diff --git a/datafusion/functions/src/planner.rs b/datafusion/functions/src/planner.rsindex ad42c5edd6..93edec7ece 100644--- a/datafusion/functions/src/planner.rs+++ b/datafusion/functions/src/planner.rs@@ -24,7 +24,7 @@ use datafusion_expr::{Expr,};-#[derive(Default)]+#[derive(Default, Debug)]pub struct UserDefinedFunctionPlanner;impl ExprPlanner for UserDefinedFunctionPlanner {diff --git a/datafusion/substrait/tests/cases/roundtrip_logical_plan.rs b/datafusion/substrait/tests/cases/roundtrip_logical_plan.rsindex ea85092f7a..f7686bec54 100644--- a/datafusion/substrait/tests/cases/roundtrip_logical_plan.rs+++ b/datafusion/substrait/tests/cases/roundtrip_logical_plan.rs@@ -45,6 +45,7 @@ use substrait::proto::extensions::SimpleExtensionDeclaration;use substrait::proto::rel::RelType;use substrait::proto::{plan_rel, Plan, Rel};+#[derive(Debug)]struct MockSerializerRegistry;impl SerializerRegistry for MockSerializerRegistry {