Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support array concatenation for arrays with different dimensions #6872

Merged
merged 2 commits into from
Jul 9, 2023

Conversation

jayzhan211
Copy link
Contributor

@jayzhan211 jayzhan211 commented Jul 7, 2023

Which issue does this PR close?

Ref #6849

Rationale for this change

What changes are included in this PR?

Calculate dims for each array in concat(), find the max one, and wrap each array to the same dims.

Note that this change does not restrict that each array dimension should be diff by 1 as mentioned in the issue, but I think it is fine not to restrict that, If we need to ensure that, we just need additional error handling.

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added physical-expr Physical Expressions core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) labels Jul 7, 2023
@alamb
Copy link
Contributor

alamb commented Jul 7, 2023

@izveigor do you have time to review this PR, perhaps?

@@ -365,6 +365,31 @@ select array_concat(make_array(), make_array(2, 3));
----
[2, 3]

# array_concat with different dimensions
Copy link
Contributor

Choose a reason for hiding this comment

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

In my opinion, it would be better to write # array_concat with different dimensions #1 (2D + 1D) in all test cases (where 1 is the test case number).

select array_concat(make_array(10, 20), make_array([30, 40]), make_array([[50, 60]]))
----
[[[10, 20]], [[30, 40]], [[50, 60]]]

Copy link
Contributor

Choose a reason for hiding this comment

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

We also have test cases with the concatenation operator.
Could you please write some test cases with it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR fails on the concatenation operator. I will request another PR on this.


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
Copy link
Contributor

Choose a reason for hiding this comment

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

let args_ndim = args.iter().map(|arr| compute_array_ndims(0, arr.clone).max()?;

Copy link
Contributor

@izveigor izveigor left a comment

Choose a reason for hiding this comment

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

Thank you, @jayzhan211!
I left a few minor nitpicks. But I think that the code does not contain serious errors.

@jayzhan211 jayzhan211 marked this pull request as draft July 7, 2023 23:37
Signed-off-by: jayzhan211 <[email protected]>
@jayzhan211 jayzhan211 marked this pull request as ready for review July 8, 2023 00:23
@alamb alamb changed the title Add diff dims support for array concat Support array concatenation for arrays with different dimensions Jul 9, 2023
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you @jayzhan211 and @izveigor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate physical-expr Physical Expressions sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants