Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
Signed-off-by: jayzhan211 <[email protected]>
  • Loading branch information
jayzhan211 committed Jul 8, 2023
1 parent 4d6e013 commit ab4f6a8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
9 changes: 4 additions & 5 deletions datafusion/core/tests/sqllogictests/test_files/array.slt
Original file line number Diff line number Diff line change
Expand Up @@ -365,26 +365,25 @@ select array_concat(make_array(), make_array(2, 3));
----
[2, 3]

# array_concat with different dimensions
# 2D + 1D
# array_concat with different dimensions #1 (2D + 1D)
query ?
select array_concat(make_array([1,2], [3,4]), make_array(5, 6))
----
[[1, 2], [3, 4], [5, 6]]

# 1D + 2D
# array_concat with different dimensions #2 (1D + 2D)
query ?
select array_concat(make_array(5, 6), make_array([1,2], [3,4]))
----
[[5, 6], [1, 2], [3, 4]]

# 2D + 1D + 1D
# array_concat with different dimensions #3 (2D + 1D + 1D)
query ?
select array_concat(make_array([1,2], [3,4]), make_array(5, 6), make_array(7,8))
----
[[1, 2], [3, 4], [5, 6], [7, 8]]

# 1D + 2D + 3D
# array_concat with different dimensions #4 (1D + 2D + 3D)
query ?
select array_concat(make_array(10, 20), make_array([30, 40]), make_array([[50, 60]]))
----
Expand Down
13 changes: 6 additions & 7 deletions datafusion/physical-expr/src/array_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,15 +400,14 @@ fn compute_array_ndims(arg: u8, arr: ArrayRef) -> Result<u8> {
}

fn align_array_dimensions(args: Vec<ArrayRef>) -> Result<Vec<ArrayRef>> {
// Compute the number of dimensions for each array
let args_ndim: Result<Vec<u8>> = args
// Find the maximum number of dimensions
let max_ndim: u8 = *args
.iter()
.map(|arr| compute_array_ndims(0, arr.clone()))
.collect();
let args_ndim = args_ndim?;

// Find the maximum number of dimensions
let max_ndim = *args_ndim.iter().max().unwrap();
.collect::<Result<Vec<u8>>>()?
.iter()
.max()
.unwrap();

// Align the dimensions of the arrays
let aligned_args: Result<Vec<ArrayRef>> = args
Expand Down

0 comments on commit ab4f6a8

Please sign in to comment.