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

Update REVERSE scalar function to support Utf8View #11973

Merged
merged 1 commit into from
Aug 15, 2024

Conversation

Omega359
Copy link
Contributor

Which issue does this PR close?

Closes #11915

Rationale for this change

Update reverse udf to support utf8view

What changes are included in this PR?

code, tests

Are these changes tested?

Yes

Are there any user-facing changes?

No

@github-actions github-actions bot added sqllogictest SQL Logic Tests (.slt) functions labels Aug 14, 2024
@Omega359 Omega359 marked this pull request as ready for review August 14, 2024 13:00
@@ -83,10 +85,17 @@ impl ScalarUDFImpl for ReverseFunc {
/// reverse('abcde') = 'edcba'
/// The implementation uses UTF-8 code points as characters
pub fn reverse<T: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<ArrayRef> {
let string_array = as_generic_string_array::<T>(&args[0])?;
if args[0].data_type() == &Utf8View {
Copy link
Contributor

Choose a reason for hiding this comment

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

probably we can keep same pattern like in invoke ? it would be more readable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as in using a match? Sure. It won't be the same match arms though.


use datafusion_common::{Result, ScalarValue};
use datafusion_expr::{ColumnarValue, ScalarUDFImpl};

use crate::unicode::reverse::ReverseFunc;
use crate::utils::test::test_function;

macro_rules! test_reverse {
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to have a function rather than macro?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could, sure. I'm curious as to why though. This is just the same approach as I used for lpad.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah this testing pattern is somewhat common in the string functions

I happen to like .slt in general, but I know that is not for everyone

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, we trying to use macros if other options didn't work. It takes more time when people debug tests to expand the macros and go through them.

if its already used in string tests its okay, perhaps we want to revisit macros and replace them with funcs whenever possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great explanation ,thanks.

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.

Makes sense to me. Thanks @Omega359 and @comphead


use datafusion_common::{Result, ScalarValue};
use datafusion_expr::{ColumnarValue, ScalarUDFImpl};

use crate::unicode::reverse::ReverseFunc;
use crate::utils::test::test_function;

macro_rules! test_reverse {
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah this testing pattern is somewhat common in the string functions

I happen to like .slt in general, but I know that is not for everyone

@alamb alamb merged commit 06bcf33 into apache:main Aug 15, 2024
24 checks passed
@alamb
Copy link
Contributor

alamb commented Aug 15, 2024

THanks again @Omega359 and @comphead

@Omega359 Omega359 deleted the feature/reverse_utf8view branch October 6, 2024 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
functions sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update REVERSE scalar function to support Utf8View
3 participants