Skip to content

Commit

Permalink
Fix output for named_struct when inputs are scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
mwylde committed Oct 21, 2024
1 parent f2792f6 commit 6851c30
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion datafusion/functions/src/core/named_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ fn named_struct_expr(args: &[ColumnarValue]) -> Result<ColumnarValue> {
);
}

let all_scalar = args.iter().all(|arg| matches!(arg, ColumnarValue::Scalar(_)));

let (names, values): (Vec<_>, Vec<_>) = args
.chunks_exact(2)
.enumerate()
Expand Down Expand Up @@ -70,7 +72,13 @@ fn named_struct_expr(args: &[ColumnarValue]) -> Result<ColumnarValue> {
})
.collect::<Vec<_>>();

Ok(ColumnarValue::Array(Arc::new(StructArray::from(fields))))
let struct_array = Arc::new(StructArray::from(fields));

if all_scalar {
Ok(ColumnarValue::Scalar(ScalarValue::Struct(struct_array)))
} else {
Ok(ColumnarValue::Array(struct_array))
}
}

#[derive(Debug)]
Expand Down

0 comments on commit 6851c30

Please sign in to comment.