Skip to content

Apache DataFusion SQL Query Engine

Minor: assorted schema handling debug improvements (#6076)

Marco Neumann48c72c69e96a
diff --git a/datafusion/common/src/dfschema.rs b/datafusion/common/src/dfschema.rs
index 295577dafa..1686a5d0df 100644
--- a/datafusion/common/src/dfschema.rs
+++ b/datafusion/common/src/dfschema.rs
@@ -601,7 +601,7 @@ impl Display for DFSchema {
///
/// Note that this trait is implemented for &[DFSchema] which is
/// widely used in the DataFusion codebase.
-pub trait ExprSchema {
+pub trait ExprSchema: std::fmt::Debug {
/// Is this column reference nullable?
fn nullable(&self, col: &Column) -> Result<bool>;
@@ -610,7 +610,7 @@ pub trait ExprSchema {
}
// Implement `ExprSchema` for `Arc<DFSchema>`
-impl<P: AsRef<DFSchema>> ExprSchema for P {
+impl<P: AsRef<DFSchema> + std::fmt::Debug> ExprSchema for P {
fn nullable(&self, col: &Column) -> Result<bool> {
self.as_ref().nullable(col)
}
diff --git a/datafusion/expr/src/expr_schema.rs b/datafusion/expr/src/expr_schema.rs
index 685d348ced..4e08860cce 100644
--- a/datafusion/expr/src/expr_schema.rs
+++ b/datafusion/expr/src/expr_schema.rs
@@ -375,6 +375,7 @@ mod tests {
);
}
+ #[derive(Debug)]
struct MockExprSchema {
nullable: bool,
data_type: DataType,
diff --git a/datafusion/expr/src/field_util.rs b/datafusion/expr/src/field_util.rs
index 985e92d437..8f5d6a6e34 100644
--- a/datafusion/expr/src/field_util.rs
+++ b/datafusion/expr/src/field_util.rs
@@ -51,9 +51,8 @@ pub fn get_indexed_field(data_type: &DataType, key: &ScalarValue) -> Result<Fiel
(DataType::List(_), _) => Err(DataFusionError::Plan(
"Only ints are valid as an indexed field in a list".to_string(),
)),
- _ => Err(DataFusionError::Plan(
- "The expression to get an indexed field is only valid for `List` types"
- .to_string(),
+ (other, _) => Err(DataFusionError::Plan(
+ format!("The expression to get an indexed field is only valid for `List` or `Struct` types, got {other}")
)),
}
}