Skip to content

Commit 76681d6

Browse files
committed
Reordered CastColumnExpr::build to validate Column index/field against
the input schema before resolving the expression data type, preserving existing type compatibility checks and error messages.
1 parent 110daf6 commit 76681d6

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

datafusion/physical-expr/src/expressions/cast_column.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,6 @@ impl CastColumnExpr {
104104
input_schema: Arc<Schema>,
105105
) -> Result<Self> {
106106
let cast_options = normalize_cast_options(cast_options);
107-
let expr_data_type = expr.data_type(input_schema.as_ref())?;
108-
if input_field.data_type() != &expr_data_type {
109-
return plan_err!(
110-
"CastColumnExpr input field data type '{}' does not match expression data type '{}'",
111-
input_field.data_type(),
112-
expr_data_type
113-
);
114-
}
115107
if let Some(column) = expr.as_any().downcast_ref::<Column>() {
116108
let fields = input_schema.fields();
117109
let Some(schema_field) = fields.get(column.index()) else {
@@ -134,6 +126,14 @@ impl CastColumnExpr {
134126
);
135127
}
136128
}
129+
let expr_data_type = expr.data_type(input_schema.as_ref())?;
130+
if input_field.data_type() != &expr_data_type {
131+
return plan_err!(
132+
"CastColumnExpr input field data type '{}' does not match expression data type '{}'",
133+
input_field.data_type(),
134+
expr_data_type
135+
);
136+
}
137137

138138
match (input_field.data_type(), target_field.data_type()) {
139139
(DataType::Struct(source_fields), DataType::Struct(target_fields)) => {

0 commit comments

Comments
 (0)