Skip to content

Apache DataFusion SQL Query Engine

Improve error message and comments (#641)

Andrew Lamb466b7c5722b6
diff --git a/datafusion/src/logical_plan/dfschema.rs b/datafusion/src/logical_plan/dfschema.rs
index b46e067a26..b4d864f55e 100644
--- a/datafusion/src/logical_plan/dfschema.rs
+++ b/datafusion/src/logical_plan/dfschema.rs
@@ -158,8 +158,8 @@ impl DFSchema {
}
}
Err(DataFusionError::Plan(format!(
- "No field matches column '{}'",
- col,
+ "No field matches column '{}'. Available fields: {}",
+ col, self
)))
}
diff --git a/datafusion/src/logical_plan/expr.rs b/datafusion/src/logical_plan/expr.rs
index 1bf3b65d9a..1fab9bb875 100644
--- a/datafusion/src/logical_plan/expr.rs
+++ b/datafusion/src/logical_plan/expr.rs
@@ -83,7 +83,12 @@ impl Column {
}
}
- /// Normalize Column with qualifier based on provided dataframe schemas.
+ /// Normalizes `self` if is unqualified (has no relation name)
+ /// with an explicit qualifier from the first matching input
+ /// schemas.
+ ///
+ /// For example, `foo` will be normalized to `t.foo` if there is a
+ /// column named `foo` in a relation named `t` found in `schemas`
pub fn normalize(self, schemas: &[&DFSchemaRef]) -> Result<Self> {
if self.relation.is_some() {
return Ok(self);
@@ -1113,7 +1118,8 @@ pub fn columnize_expr(e: Expr, input_schema: &DFSchema) -> Expr {
}
}
-/// Recursively normalize all Column expressions in a given expression tree
+/// Recursively call [`Column::normalize`] on all Column expressions
+/// in the `expr` expression tree.
pub fn normalize_col(e: Expr, schemas: &[&DFSchemaRef]) -> Result<Expr> {
struct ColumnNormalizer<'a, 'b> {
schemas: &'a [&'b DFSchemaRef],