alamb commented on code in PR #9743:
URL: https://github.com/apache/arrow-datafusion/pull/9743#discussion_r1543273506
##########
datafusion/sqllogictest/test_files/struct.slt:
##########
@@ -63,10 +69,10 @@ query TT
explain select struct(a, b, c) from values;
----
logical_plan
-Projection: struct(values.a, values.b, values.c)
+Projection: named_struct(Utf8("c0"), values.a, Utf8("c1"), values.b,
Utf8("c2"), values.c)
--TableScan: values projection=[a, b, c]
physical_plan
-ProjectionExec: expr=[struct(a@0, b@1, c@2) as
struct(values.a,values.b,values.c)]
+ProjectionExec: expr=[named_struct(c0, a@0, c1, b@1, c2, c@2) as
named_struct(Utf8("c0"),values.a,Utf8("c1"),values.b,Utf8("c2"),values.c)]
Review Comment:
Filed https://github.com/apache/arrow-datafusion/issues/9839 for follow up
##########
datafusion/functions/src/core/named_struct.rs:
##########
@@ -27,40 +27,50 @@ use std::sync::Arc;
fn named_struct_expr(args: &[ColumnarValue]) -> Result<ColumnarValue> {
// do not accept 0 arguments.
if args.is_empty() {
- return exec_err!("named_struct requires at least one pair of
arguments");
+ return exec_err!("named_struct requires at least one pair of
arguments, got 0 instead");
}
if args.len() % 2 != 0 {
- return exec_err!("named_struct requires an even number of arguments");
+ return exec_err!("named_struct requires an even number of arguments,
got {} instead", args.len());
}
- let fields = args
+ let (names, values): (Vec<_>, Vec<_>) = args
.chunks_exact(2)
- .map(|chunk| {
- let name = &chunk[0];
- let value = &chunk[1];
-
- if let ColumnarValue::Scalar(ScalarValue::Utf8(Some(name))) = name
{
- let array_ref = match value {
- ColumnarValue::Array(array) => array.clone(),
- ColumnarValue::Scalar(scalar) =>
scalar.to_array()?.clone(),
- };
-
- Ok((
- Arc::new(Field::new(
- name.clone(),
- array_ref.data_type().clone(),
- true,
- )),
- array_ref,
- ))
- } else {
- exec_err!("named_struct even arguments must be string
literals")
- }
+ .enumerate()
+ .map(|(i, chunk)| {
+
+ let name_column = &chunk[0];
+
+ let name = match name_column {
+ ColumnarValue::Scalar(ScalarValue::Utf8(Some(name_scalar))) =>
name_scalar,
+ _ => return exec_err!("named_struct even arguments must be
string literals, got {name_column:?} instead at position {}", i * 2)
Review Comment:
❤️
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]