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/11953: Support StringView for TRANSLATE() fn #11967

Merged
merged 9 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion datafusion/functions/src/unicode/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ impl TranslateFunc {
use DataType::*;
Self {
signature: Signature::one_of(
vec![Exact(vec![Utf8, Utf8, Utf8])],
vec![
Exact(vec![Utf8View, Utf8, Utf8]),
Exact(vec![Utf8, Utf8, Utf8])
],
Volatility::Immutable,
),
}
Expand All @@ -72,6 +75,7 @@ impl ScalarUDFImpl for TranslateFunc {

fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue> {
match args[0].data_type() {
DataType::Utf8View => make_scalar_function(translate::<i32>, vec![])(args),
Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect this I think you'll likely also need to change the implementation of translate as well (see for example what @PsiACE has done in #11970)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good I'll take a look 👍

DataType::Utf8 => make_scalar_function(translate::<i32>, vec![])(args),
DataType::LargeUtf8 => make_scalar_function(translate::<i64>, vec![])(args),
other => {
Expand Down
3 changes: 1 addition & 2 deletions datafusion/sqllogictest/test_files/string_view.slt
Original file line number Diff line number Diff line change
Expand Up @@ -895,14 +895,13 @@ logical_plan
02)--TableScan: test projection=[column1_utf8view, column2_utf8view]

## Ensure no casts for TRANSLATE
## TODO file ticket
query TT
EXPLAIN SELECT
TRANSLATE(column1_utf8view, 'foo', 'bar') as c
FROM test;
----
logical_plan
01)Projection: translate(CAST(test.column1_utf8view AS Utf8), Utf8("foo"), Utf8("bar")) AS c
01)Projection: translate(test.column1_utf8view, Utf8("foo"), Utf8("bar")) AS c
02)--TableScan: test projection=[column1_utf8view]

## Ensure no casts for FIND_IN_SET
Expand Down
Loading