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

Implement native stringview support for BTRIM #11920

Merged
merged 6 commits into from
Aug 12, 2024

Conversation

Kev1n8
Copy link
Contributor

@Kev1n8 Kev1n8 commented Aug 9, 2024

Which issue does this PR close?

Closes #11835

Rationale for this change

What changes are included in this PR?

The changes mainly lie in datafusion/functions/string/common.rs, where I broke generic_trim up to deal with 2 conditions (whether to use Utf8View or not). An additional parameter is also added to indicate the datatype. I also temporarily adjusted LTRIM and RTRIM to work through the process. If my implementation is considered a good practice, I would like to open follow-on PRs to have LTRIM and RTRIM support Utf8View natively.

And some tests were also added to string_view.slt covering the Utf8View support of BTRIM.

Are these changes tested?

yes

Are there any user-facing changes?

no

@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Aug 9, 2024
@Kev1n8
Copy link
Contributor Author

Kev1n8 commented Aug 9, 2024

Just an info: I tried combining the two functions string_view_trim and string_trim by treating StringArray and StringViewArray as something like dyn Array + ArrayAccessor. But the trait of value() between these two actually differs. StringArray impls value() by impl ArrayAccessor while it comes with no ArrayAccessor of StringViewArray, it is instead directly impl.

@Kev1n8 Kev1n8 changed the title Add stringview support for BTRIM Implement native stringview support for BTRIM Aug 10, 2024
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 @Kev1n8 -- I think this PR is an improvement for sure.

}

// removing 'a will cause compiler complaining lifetime of `func`
fn string_view_trim<'a, T: OffsetSizeTrait>(
Copy link
Contributor

@alamb alamb Aug 12, 2024

Choose a reason for hiding this comment

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

This implementation is an improvement -- however, it will now copy the string values to a new StringArray

I think if the function generated StringView output directly it would be possible to avoid all string copies (and only adjust the views).

I can file this as a follow on optimization idea.

I noticed this on #11790

@alamb alamb merged commit 34ec9d4 into apache:main Aug 12, 2024
27 checks passed
@Kev1n8 Kev1n8 deleted the add-stringview-support-for-btrim branch August 12, 2024 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update the BTRIM scalar function to support Utf8View
2 participants