Skip to content

Commit 4df83f5

Browse files
authored
Derive Debug for SessionStateBuilder, adding Debug requirements to fields (#12632)
* Require Debug for PhysicalOptimizerRule * Add reference to meet &JoinType type required * Revert "Add reference to meet &JoinType type required" as clippy lint informs this is unnecessary This reverts commit f69d73c. * Require `Debug` for `CatalogProvider`, `CatalogProviderList`, UrlTableFactory * Add derive Debug to meet api-change * Add derive Debug in datafusion-cli to support api-change of CatalogProviderList * Require Debug for ExprPlanner * Require Debug for QueryPlanner * Require Debug for TableFunctionImpl * Require Debug for SerializerRegistry * Require Debug for FunctionFactory * Derive `Debug` on `SessionStateBuilder` * Implement `Debug` for `SessionStateBuilder` to reorder output fields, keep consistent Debug field order with `SessionState` * Settle TODO for displaying `Debug` of `InformationSchemaConfig` after `CatalogProviderList` requires `Debug`
1 parent 0abae43 commit 4df83f5

File tree

24 files changed

+91
-35
lines changed

24 files changed

+91
-35
lines changed

datafusion-cli/src/catalog.rs

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use dirs::home_dir;
3434
use parking_lot::RwLock;
3535

3636
/// Wraps another catalog, automatically register require object stores for the file locations
37+
#[derive(Debug)]
3738
pub struct DynamicObjectStoreCatalog {
3839
inner: Arc<dyn CatalogProviderList>,
3940
state: Weak<RwLock<SessionState>>,
@@ -74,6 +75,7 @@ impl CatalogProviderList for DynamicObjectStoreCatalog {
7475
}
7576

7677
/// Wraps another catalog provider
78+
#[derive(Debug)]
7779
struct DynamicObjectStoreCatalogProvider {
7880
inner: Arc<dyn CatalogProvider>,
7981
state: Weak<RwLock<SessionState>>,
@@ -115,6 +117,7 @@ impl CatalogProvider for DynamicObjectStoreCatalogProvider {
115117

116118
/// Wraps another schema provider. [DynamicObjectStoreSchemaProvider] is responsible for registering the required
117119
/// object stores for the file locations.
120+
#[derive(Debug)]
118121
struct DynamicObjectStoreSchemaProvider {
119122
inner: Arc<dyn SchemaProvider>,
120123
state: Weak<RwLock<SessionState>>,

datafusion-cli/src/functions.rs

+1
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ fn fixed_len_byte_array_to_string(val: Option<&FixedLenByteArray>) -> Option<Str
315315
})
316316
}
317317

318+
#[derive(Debug)]
318319
pub struct ParquetMetadataFunc {}
319320

320321
impl TableFunctionImpl for ParquetMetadataFunc {

datafusion-examples/examples/catalog.rs

+3
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ struct DirSchemaOpts<'a> {
135135
format: Arc<dyn FileFormat>,
136136
}
137137
/// Schema where every file with extension `ext` in a given `dir` is a table.
138+
#[derive(Debug)]
138139
struct DirSchema {
139140
ext: String,
140141
tables: RwLock<HashMap<String, Arc<dyn TableProvider>>>,
@@ -218,6 +219,7 @@ impl SchemaProvider for DirSchema {
218219
}
219220
}
220221
/// Catalog holds multiple schemas
222+
#[derive(Debug)]
221223
struct DirCatalog {
222224
schemas: RwLock<HashMap<String, Arc<dyn SchemaProvider>>>,
223225
}
@@ -259,6 +261,7 @@ impl CatalogProvider for DirCatalog {
259261
}
260262
}
261263
/// Catalog lists holds multiple catalog providers. Each context has a single catalog list.
264+
#[derive(Debug)]
262265
struct CustomCatalogProviderList {
263266
catalogs: RwLock<HashMap<String, Arc<dyn CatalogProvider>>>,
264267
}

datafusion-examples/examples/simple_udtf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ impl TableProvider for LocalCsvTable {
128128
}
129129
}
130130

131+
#[derive(Debug)]
131132
struct LocalCsvTableFunc {}
132133

133134
impl TableFunctionImpl for LocalCsvTableFunc {

datafusion/catalog/src/catalog.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717

1818
use std::any::Any;
19+
use std::fmt::Debug;
1920
use std::sync::Arc;
2021

2122
pub use crate::schema::SchemaProvider;
@@ -101,7 +102,7 @@ use datafusion_common::Result;
101102
///
102103
/// [`TableProvider`]: crate::TableProvider
103104
104-
pub trait CatalogProvider: Sync + Send {
105+
pub trait CatalogProvider: Debug + Sync + Send {
105106
/// Returns the catalog provider as [`Any`]
106107
/// so that it can be downcast to a specific implementation.
107108
fn as_any(&self) -> &dyn Any;
@@ -152,7 +153,7 @@ pub trait CatalogProvider: Sync + Send {
152153
///
153154
/// Please see the documentation on `CatalogProvider` for details of
154155
/// implementing a custom catalog.
155-
pub trait CatalogProviderList: Sync + Send {
156+
pub trait CatalogProviderList: Debug + Sync + Send {
156157
/// Returns the catalog list as [`Any`]
157158
/// so that it can be downcast to a specific implementation.
158159
fn as_any(&self) -> &dyn Any;

datafusion/catalog/src/dynamic_file/catalog.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
use crate::{CatalogProvider, CatalogProviderList, SchemaProvider, TableProvider};
2121
use async_trait::async_trait;
2222
use std::any::Any;
23+
use std::fmt::Debug;
2324
use std::sync::Arc;
2425

2526
/// Wrap another catalog provider list
27+
#[derive(Debug)]
2628
pub struct DynamicFileCatalog {
2729
/// The inner catalog provider list
2830
inner: Arc<dyn CatalogProviderList>,
@@ -67,6 +69,7 @@ impl CatalogProviderList for DynamicFileCatalog {
6769
}
6870

6971
/// Wraps another catalog provider
72+
#[derive(Debug)]
7073
struct DynamicFileCatalogProvider {
7174
/// The inner catalog provider
7275
inner: Arc<dyn CatalogProvider>,
@@ -114,6 +117,7 @@ impl CatalogProvider for DynamicFileCatalogProvider {
114117
///
115118
/// The provider will try to create a table provider from the file path if the table provider
116119
/// isn't exist in the inner schema provider.
120+
#[derive(Debug)]
117121
pub struct DynamicFileSchemaProvider {
118122
/// The inner schema provider
119123
inner: Arc<dyn SchemaProvider>,
@@ -174,7 +178,7 @@ impl SchemaProvider for DynamicFileSchemaProvider {
174178

175179
/// [UrlTableFactory] is a factory that can create a table provider from the given url.
176180
#[async_trait]
177-
pub trait UrlTableFactory: Sync + Send {
181+
pub trait UrlTableFactory: Debug + Sync + Send {
178182
/// create a new table provider from the provided url
179183
async fn try_new(
180184
&self,

datafusion/catalog/src/schema.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use async_trait::async_trait;
2222
use datafusion_common::{exec_err, DataFusionError};
2323
use std::any::Any;
24+
use std::fmt::Debug;
2425
use std::sync::Arc;
2526

2627
use crate::table::TableProvider;
@@ -32,7 +33,7 @@ use datafusion_common::Result;
3233
///
3334
/// [`CatalogProvider`]: super::CatalogProvider
3435
#[async_trait]
35-
pub trait SchemaProvider: Sync + Send {
36+
pub trait SchemaProvider: Debug + Sync + Send {
3637
/// Returns the owner of the Schema, default is None. This value is reported
3738
/// as part of `information_tables.schemata
3839
fn owner_name(&self) -> Option<&str> {

datafusion/catalog/src/session.rs

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ impl From<&dyn Session> for TaskContext {
139139
}
140140
type SessionRefLock = Arc<Mutex<Option<Weak<RwLock<dyn Session>>>>>;
141141
/// The state store that stores the reference of the runtime session state.
142+
#[derive(Debug)]
142143
pub struct SessionStore {
143144
session: SessionRefLock,
144145
}

datafusion/core/src/catalog_common/information_schema.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use arrow::{
2626
};
2727
use async_trait::async_trait;
2828
use datafusion_common::DataFusionError;
29-
use std::fmt::{Debug, Formatter};
29+
use std::fmt::Debug;
3030
use std::{any::Any, sync::Arc};
3131

3232
use crate::catalog::{CatalogProviderList, SchemaProvider, TableProvider};
@@ -57,6 +57,7 @@ pub const INFORMATION_SCHEMA_TABLES: &[&str] =
5757
/// demand. This means that if more tables are added to the underlying
5858
/// providers, they will appear the next time the `information_schema`
5959
/// table is queried.
60+
#[derive(Debug)]
6061
pub struct InformationSchemaProvider {
6162
config: InformationSchemaConfig,
6263
}
@@ -70,20 +71,11 @@ impl InformationSchemaProvider {
7071
}
7172
}
7273

73-
#[derive(Clone)]
74+
#[derive(Clone, Debug)]
7475
struct InformationSchemaConfig {
7576
catalog_list: Arc<dyn CatalogProviderList>,
7677
}
7778

78-
impl Debug for InformationSchemaConfig {
79-
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
80-
f.debug_struct("InformationSchemaConfig")
81-
// TODO it would be great to print the catalog list here
82-
// but that would require CatalogProviderList to implement Debug
83-
.finish_non_exhaustive()
84-
}
85-
}
86-
8779
impl InformationSchemaConfig {
8880
/// Construct the `information_schema.tables` virtual table
8981
async fn make_tables(

datafusion/core/src/catalog_common/listing_schema.rs

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ use object_store::ObjectStore;
4848
/// - `s3://host.example.com:3000/data/tpch/customer/_delta_log/`
4949
///
5050
/// [`ObjectStore`]: object_store::ObjectStore
51+
#[derive(Debug)]
5152
pub struct ListingSchemaProvider {
5253
authority: String,
5354
path: object_store::path::Path,

datafusion/core/src/catalog_common/memory.rs

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use std::any::Any;
2828
use std::sync::Arc;
2929

3030
/// Simple in-memory list of catalogs
31+
#[derive(Debug)]
3132
pub struct MemoryCatalogProviderList {
3233
/// Collection of catalogs containing schemas and ultimately TableProviders
3334
pub catalogs: DashMap<String, Arc<dyn CatalogProvider>>,
@@ -71,6 +72,7 @@ impl CatalogProviderList for MemoryCatalogProviderList {
7172
}
7273

7374
/// Simple in-memory implementation of a catalog.
75+
#[derive(Debug)]
7476
pub struct MemoryCatalogProvider {
7577
schemas: DashMap<String, Arc<dyn SchemaProvider>>,
7678
}
@@ -136,6 +138,7 @@ impl CatalogProvider for MemoryCatalogProvider {
136138
}
137139

138140
/// Simple in-memory implementation of a schema.
141+
#[derive(Debug)]
139142
pub struct MemorySchemaProvider {
140143
tables: DashMap<String, Arc<dyn TableProvider>>,
141144
}
@@ -248,6 +251,7 @@ mod test {
248251
#[test]
249252
fn default_register_schema_not_supported() {
250253
// mimic a new CatalogProvider and ensure it does not support registering schemas
254+
#[derive(Debug)]
251255
struct TestProvider {}
252256
impl CatalogProvider for TestProvider {
253257
fn as_any(&self) -> &dyn Any {

datafusion/core/src/datasource/dynamic_file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::error::Result;
3030
use crate::execution::context::SessionState;
3131

3232
/// [DynamicListTableFactory] is a factory that can create a [ListingTable] from the given url.
33-
#[derive(Default)]
33+
#[derive(Default, Debug)]
3434
pub struct DynamicListTableFactory {
3535
/// The session store that contains the current session.
3636
session_store: SessionStore,

datafusion/core/src/datasource/function.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ use super::TableProvider;
2222
use datafusion_common::Result;
2323
use datafusion_expr::Expr;
2424

25+
use std::fmt::Debug;
2526
use std::sync::Arc;
2627

2728
/// A trait for table function implementations
28-
pub trait TableFunctionImpl: Sync + Send {
29+
pub trait TableFunctionImpl: Debug + Sync + Send {
2930
/// Create a table provider
3031
fn call(&self, args: &[Expr]) -> Result<Arc<dyn TableProvider>>;
3132
}
3233

3334
/// A table that uses a function to generate data
35+
#[derive(Debug)]
3436
pub struct TableFunction {
3537
/// Name of the table function
3638
name: String,

datafusion/core/src/execution/context/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,7 @@ impl From<SessionContext> for SessionStateBuilder {
15471547

15481548
/// A planner used to add extensions to DataFusion logical and physical plans.
15491549
#[async_trait]
1550-
pub trait QueryPlanner {
1550+
pub trait QueryPlanner: Debug {
15511551
/// Given a `LogicalPlan`, create an [`ExecutionPlan`] suitable for execution
15521552
async fn create_physical_plan(
15531553
&self,
@@ -1560,7 +1560,7 @@ pub trait QueryPlanner {
15601560
/// and interact with [SessionState] to registers new udf, udaf or udwf.
15611561
15621562
#[async_trait]
1563-
pub trait FunctionFactory: Sync + Send {
1563+
pub trait FunctionFactory: Debug + Sync + Send {
15641564
/// Handles creation of user defined function specified in [CreateFunction] statement
15651565
async fn create(
15661566
&self,
@@ -1583,6 +1583,7 @@ pub enum RegisterFunction {
15831583

15841584
/// Default implementation of [SerializerRegistry] that throws unimplemented error
15851585
/// for all requests.
1586+
#[derive(Debug)]
15861587
pub struct EmptySerializerRegistry;
15871588

15881589
impl SerializerRegistry for EmptySerializerRegistry {
@@ -2129,6 +2130,7 @@ mod tests {
21292130
}
21302131
}
21312132

2133+
#[derive(Debug)]
21322134
struct MyQueryPlanner {}
21332135

21342136
#[async_trait]

datafusion/core/src/execution/session_state.rs

+42-10
Original file line numberDiff line numberDiff line change
@@ -177,23 +177,23 @@ impl Debug for SessionState {
177177
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
178178
f.debug_struct("SessionState")
179179
.field("session_id", &self.session_id)
180-
.field("analyzer", &"...")
180+
.field("config", &self.config)
181+
.field("runtime_env", &self.runtime_env)
182+
.field("catalog_list", &"...")
183+
.field("serializer_registry", &"...")
184+
.field("execution_props", &self.execution_props)
185+
.field("table_options", &self.table_options)
186+
.field("table_factories", &"...")
187+
.field("function_factory", &"...")
181188
.field("expr_planners", &"...")
189+
.field("query_planner", &"...")
190+
.field("analyzer", &"...")
182191
.field("optimizer", &"...")
183192
.field("physical_optimizers", &"...")
184-
.field("query_planner", &"...")
185-
.field("catalog_list", &"...")
186193
.field("table_functions", &"...")
187194
.field("scalar_functions", &self.scalar_functions)
188195
.field("aggregate_functions", &self.aggregate_functions)
189196
.field("window_functions", &self.window_functions)
190-
.field("serializer_registry", &"...")
191-
.field("config", &self.config)
192-
.field("table_options", &self.table_options)
193-
.field("execution_props", &self.execution_props)
194-
.field("table_factories", &"...")
195-
.field("runtime_env", &self.runtime_env)
196-
.field("function_factory", &"...")
197197
.finish_non_exhaustive()
198198
}
199199
}
@@ -1519,6 +1519,37 @@ impl SessionStateBuilder {
15191519
}
15201520
}
15211521

1522+
impl Debug for SessionStateBuilder {
1523+
/// Prefer having short fields at the top and long vector fields near the end
1524+
/// Group fields by
1525+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1526+
f.debug_struct("SessionStateBuilder")
1527+
.field("session_id", &self.session_id)
1528+
.field("config", &self.config)
1529+
.field("runtime_env", &self.runtime_env)
1530+
.field("catalog_list", &self.catalog_list)
1531+
.field("serializer_registry", &self.serializer_registry)
1532+
.field("file_formats", &self.file_formats)
1533+
.field("execution_props", &self.execution_props)
1534+
.field("table_options", &self.table_options)
1535+
.field("table_factories", &self.table_factories)
1536+
.field("function_factory", &self.function_factory)
1537+
.field("expr_planners", &self.expr_planners)
1538+
.field("query_planners", &self.query_planner)
1539+
.field("analyzer_rules", &self.analyzer_rules)
1540+
.field("analyzer", &self.analyzer)
1541+
.field("optimizer_rules", &self.optimizer_rules)
1542+
.field("optimizer", &self.optimizer)
1543+
.field("physical_optimizer_rules", &self.physical_optimizer_rules)
1544+
.field("physical_optimizers", &self.physical_optimizers)
1545+
.field("table_functions", &self.table_functions)
1546+
.field("scalar_functions", &self.scalar_functions)
1547+
.field("aggregate_functions", &self.aggregate_functions)
1548+
.field("window_functions", &self.window_functions)
1549+
.finish()
1550+
}
1551+
}
1552+
15221553
impl Default for SessionStateBuilder {
15231554
fn default() -> Self {
15241555
Self::new()
@@ -1795,6 +1826,7 @@ impl From<&SessionState> for TaskContext {
17951826
}
17961827

17971828
/// The query planner used if no user defined planner is provided
1829+
#[derive(Debug)]
17981830
struct DefaultQueryPlanner {}
17991831

18001832
#[async_trait]

datafusion/core/tests/user_defined/expr_planner.rs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use datafusion_expr::expr::Alias;
2929
use datafusion_expr::planner::{ExprPlanner, PlannerResult, RawBinaryExpr};
3030
use datafusion_expr::BinaryExpr;
3131

32+
#[derive(Debug)]
3233
struct MyCustomPlanner;
3334

3435
impl ExprPlanner for MyCustomPlanner {

datafusion/core/tests/user_defined/user_defined_plan.rs

+1
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ fn make_topk_context() -> SessionContext {
312312

313313
// ------ The implementation of the TopK code follows -----
314314

315+
#[derive(Debug)]
315316
struct TopKQueryPlanner {}
316317

317318
#[async_trait]

datafusion/core/tests/user_defined/user_defined_table_functions.rs

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ impl SimpleCsvTable {
192192
}
193193
}
194194

195+
#[derive(Debug)]
195196
struct SimpleCsvTableFunc {}
196197

197198
impl TableFunctionImpl for SimpleCsvTableFunc {

0 commit comments

Comments
 (0)