Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions datafusion/expr/src/built_in_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ use crate::signature::TIMEZONE_WILDCARD;
use crate::type_coercion::binary::get_wider_type;
use crate::type_coercion::functions::data_types;
use crate::{
conditional_expressions, struct_expressions, FuncMonotonicity, Signature,
TypeSignature, Volatility,
conditional_expressions, FuncMonotonicity, Signature, TypeSignature, Volatility,
};

use arrow::datatypes::{DataType, Field, Fields, IntervalUnit, TimeUnit};
Expand Down Expand Up @@ -971,10 +970,7 @@ impl BuiltinScalarFunction {
],
self.volatility(),
),
BuiltinScalarFunction::Struct => Signature::variadic(
struct_expressions::SUPPORTED_STRUCT_TYPES.to_vec(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can also remove SUPPORTED_STRUCT_TYPES entirely (I don't think it is used anywhere else)

We can do so as a follow on PR too.

self.volatility(),
),
BuiltinScalarFunction::Struct => Signature::variadic_any(self.volatility()),
BuiltinScalarFunction::Concat
| BuiltinScalarFunction::ConcatWithSeparator => {
Signature::variadic(vec![Utf8], self.volatility())
Expand Down
35 changes: 9 additions & 26 deletions datafusion/physical-expr/src/struct_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
//! Struct expressions

use arrow::array::*;
use arrow::datatypes::{DataType, Field};
use datafusion_common::{exec_err, not_impl_err, DataFusionError, Result};
use arrow::datatypes::Field;
use datafusion_common::{exec_err, DataFusionError, Result};
use datafusion_expr::ColumnarValue;
use std::sync::Arc;

Expand All @@ -34,31 +34,14 @@ fn array_struct(args: &[ArrayRef]) -> Result<ArrayRef> {
.enumerate()
.map(|(i, arg)| {
let field_name = format!("c{i}");
match arg.data_type() {
DataType::Utf8
| DataType::LargeUtf8
| DataType::Boolean
| DataType::Float32
| DataType::Float64
| DataType::Int8
| DataType::Int16
| DataType::Int32
| DataType::Int64
| DataType::UInt8
| DataType::UInt16
| DataType::UInt32
| DataType::UInt64 => Ok((
Arc::new(Field::new(
field_name.as_str(),
arg.data_type().clone(),
true,
)),
arg.clone(),
Ok((
Arc::new(Field::new(
field_name.as_str(),
arg.data_type().clone(),
true,
)),
data_type => {
not_impl_err!("Struct is not implemented for type '{data_type:?}'.")
}
}
arg.clone(),
))
})
.collect::<Result<Vec<_>>>()?;

Expand Down
11 changes: 11 additions & 0 deletions datafusion/sqllogictest/test_files/struct.slt
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,16 @@ select struct(a, b, c) from values;
{c0: 2, c1: 2.2, c2: b}
{c0: 3, c1: 3.3, c2: c}

# explain struct scalar function with columns #1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
I double checked and before this PR this query results in casts

❯ explain select struct(a, b, c) from values;
+---------------+----------------------------------------------------------------------------------------------------------------+
| plan_type     | plan                                                                                                           |
+---------------+----------------------------------------------------------------------------------------------------------------+
| logical_plan  | Projection: struct(CAST(values.a AS Utf8), CAST(values.b AS Utf8), values.c)                                   |
|               |   TableScan: values projection=[a, b, c]                                                                       |
| physical_plan | ProjectionExec: expr=[struct(CAST(a@0 AS Utf8), CAST(b@1 AS Utf8), c@2) as struct(values.a,values.b,values.c)] |
|               |   MemoryExec: partitions=1, partition_sizes=[1]                                                                |
|               |                                                                                                                |
+---------------+----------------------------------------------------------------------------------------------------------------+
2 rows in set. Query took 0.009 seconds.

query TT
explain select struct(a, b, c) from values;
----
logical_plan
Projection: struct(values.a, values.b, 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)]
--MemoryExec: partitions=1, partition_sizes=[1]

statement ok
drop table values;