From 5228bb31728eacb790dcbefda07b07a9d2d4b8f7 Mon Sep 17 00:00:00 2001 From: jiangzhx Date: Thu, 8 Jun 2023 12:50:00 +0800 Subject: [PATCH] Make the struct function return the correct data type. --- datafusion/expr/src/function.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/datafusion/expr/src/function.rs b/datafusion/expr/src/function.rs index ed5df5766720..bec672ab6f6c 100644 --- a/datafusion/expr/src/function.rs +++ b/datafusion/expr/src/function.rs @@ -352,7 +352,14 @@ pub fn return_type( _ => Ok(DataType::Float64), }, - BuiltinScalarFunction::Struct => Ok(DataType::Struct(Fields::empty())), + BuiltinScalarFunction::Struct => { + let return_fields = input_expr_types + .iter() + .enumerate() + .map(|(pos, dt)| Field::new(format!("c{pos}"), dt.clone(), true)) + .collect::>(); + Ok(DataType::Struct(Fields::from(return_fields))) + } BuiltinScalarFunction::Atan2 => match &input_expr_types[0] { DataType::Float32 => Ok(DataType::Float32),