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

feat: support array_reverse #9023

Merged
merged 15 commits into from
Jan 31, 2024
Merged

feat: support array_reverse #9023

merged 15 commits into from
Jan 31, 2024

Conversation

Weijun-H
Copy link
Member

Which issue does this PR close?

Closes #9021

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates sqllogictest SQL Logic Tests (.slt) labels Jan 27, 2024
@Weijun-H Weijun-H marked this pull request as ready for review January 27, 2024 15:55
Copy link
Contributor

@Jefffrey Jefffrey left a comment

Choose a reason for hiding this comment

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

Implementation seems good, just a bit unsure on dealing with null/empty arrays 🤔

Comment on lines 2776 to 2784
DataType::List(field) => {
let array = as_list_array(&arg[0])?;
general_array_reverse::<i32>(array, &field)
}
DataType::LargeList(field) => {
let array = as_large_list_array(&arg[0])?;
general_array_reverse::<i64>(array, &field)
}
DataType::Null => Ok(arg[0].clone()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Leave a TODO item/create new issue for support for reversing FixedSizeList too?

Unless you feel you can add in support for that in this PR, even though they aren't a GenericListArray underneath

Copy link
Member Author

Choose a reason for hiding this comment

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

We do not handle FixedSizeList here, which will be solved by type coercion.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah makes sense. So this would be done in a later PR, if I understand correctly?

Else if it should already work with FixedSizeList then can add that as a test case in slt

Copy link
Member Author

Choose a reason for hiding this comment

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

It is still working on other pr, so I added a TODO test in slt.

Comment on lines 2776 to 2784
DataType::List(field) => {
let array = as_list_array(&arg[0])?;
general_array_reverse::<i32>(array, &field)
}
DataType::LargeList(field) => {
let array = as_large_list_array(&arg[0])?;
general_array_reverse::<i64>(array, &field)
}
DataType::Null => Ok(arg[0].clone()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah makes sense. So this would be done in a later PR, if I understand correctly?

Else if it should already work with FixedSizeList then can add that as a test case in slt

Copy link
Contributor

@Jefffrey Jefffrey left a comment

Choose a reason for hiding this comment

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

Looks good 👍

@@ -1609,6 +1614,7 @@ impl BuiltinScalarFunction {
BuiltinScalarFunction::ArrayReplaceAll => {
&["array_replace_all", "list_replace_all"]
}
BuiltinScalarFunction::ArrayReverse => &["array_reverse", "list_reverse"],
Copy link
Contributor

Choose a reason for hiding this comment

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

clickhouse support reverse(arr), I think we can have it too.

Copy link
Member Author

@Weijun-H Weijun-H Jan 29, 2024

Choose a reason for hiding this comment

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

But reverse exists for Reverses the order of the characters in the string.
https://arrow.apache.org/datafusion/user-guide/sql/scalar_functions.html#reverse

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I didn't notice that.

Copy link
Contributor

@jayzhan211 jayzhan211 left a comment

Choose a reason for hiding this comment

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

LGTM

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.

Thanks @Weijun-H -- this looks good to me. Thank you 🙏

Can you please merge up and resolve conflicts and I think this PR will be ready to go

@Weijun-H Weijun-H force-pushed the support-array-reverse branch from f33c430 to f69c29e Compare January 31, 2024 02:16
@alamb alamb merged commit 15f59d9 into apache:main Jan 31, 2024
23 checks passed
@alamb
Copy link
Contributor

alamb commented Jan 31, 2024

Thanks again @Weijun-H @jayzhan211 and @Jefffrey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support list_reverse in array
4 participants