Skip to content

Commit

Permalink
Fix panic in struct function with mixed scalar/array arguments (apa…
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb authored Mar 24, 2024
1 parent c5faaf7 commit bd9b33c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
11 changes: 2 additions & 9 deletions datafusion/functions/src/core/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,10 @@ fn array_struct(args: &[ArrayRef]) -> Result<ArrayRef> {

Ok(Arc::new(StructArray::from(vec)))
}

/// put values in a struct array.
fn struct_expr(args: &[ColumnarValue]) -> Result<ColumnarValue> {
let arrays = args
.iter()
.map(|x| {
Ok(match x {
ColumnarValue::Array(array) => array.clone(),
ColumnarValue::Scalar(scalar) => scalar.to_array()?.clone(),
})
})
.collect::<Result<Vec<ArrayRef>>>()?;
let arrays = ColumnarValue::values_to_arrays(args)?;
Ok(ColumnarValue::Array(array_struct(arrays.as_slice())?))
}
#[derive(Debug)]
Expand Down
9 changes: 9 additions & 0 deletions datafusion/sqllogictest/test_files/struct.slt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ select struct(a, b, c) from values;
{c0: 2, c1: 2.2, c2: b}
{c0: 3, c1: 3.3, c2: c}

# struct scalar function with columns and scalars
query ?
select struct(a, 'foo') from values;
----
{c0: 1, c1: foo}
{c0: 2, c1: foo}
{c0: 3, c1: foo}


# explain struct scalar function with columns #1
query TT
explain select struct(a, b, c) from values;
Expand Down

0 comments on commit bd9b33c

Please sign in to comment.