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

Always use StringViewArray as output of substr #14498

Merged
merged 5 commits into from
Feb 8, 2025
Merged
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
Prev Previous commit
Next Next commit
fix sqllogictest/string_view
Kev1n8 committed Feb 5, 2025
commit 08210dc1daf68e817d69edd01b01d97806e39069
6 changes: 4 additions & 2 deletions datafusion/functions/src/unicode/substr.rs
Original file line number Diff line number Diff line change
@@ -21,7 +21,8 @@ use std::sync::Arc;
use crate::strings::make_and_append_view;
use crate::utils::make_scalar_function;
use arrow::array::{
Array, ArrayIter, ArrayRef, AsArray, Int64Array, OffsetSizeTrait, StringArrayType, StringViewArray, StringViewBuilder
Array, ArrayIter, ArrayRef, AsArray, Int64Array, OffsetSizeTrait, StringArrayType,
StringViewArray, StringViewBuilder,
};
use arrow::datatypes::DataType;
use arrow_buffer::{NullBufferBuilder, ScalarBuffer};
@@ -89,6 +90,7 @@ impl ScalarUDFImpl for SubstrFunc {
&self.signature
}

// `SubstrFunc` always generates `Utf8View` output for its efficiency.
fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
Ok(DataType::Utf8View)
}
@@ -181,7 +183,7 @@ impl ScalarUDFImpl for SubstrFunc {
/// substr('alphabet', 3, 2) = 'ph'
/// The implementation uses UTF-8 code points as characters
pub fn substr(args: &[ArrayRef]) -> Result<ArrayRef> {
match args[0].data_type() {
match args[0].data_type() {
DataType::Utf8 => {
let string_array = args[0].as_string::<i32>();
string_substr::<_, i32>(string_array, &args[1..])
2 changes: 1 addition & 1 deletion datafusion/sqllogictest/test_files/string/string_view.slt
Original file line number Diff line number Diff line change
@@ -382,7 +382,7 @@ EXPLAIN SELECT
FROM test;
----
logical_plan
01)Projection: starts_with(test.column1_utf8, substr(test.column1_utf8, Int64(1), Int64(2))) AS c1, starts_with(test.column1_large_utf8, substr(test.column1_large_utf8, Int64(1), Int64(2))) AS c2, starts_with(test.column1_utf8view, substr(test.column1_utf8view, Int64(1), Int64(2))) AS c3
01)Projection: starts_with(CAST(test.column1_utf8 AS Utf8View), substr(test.column1_utf8, Int64(1), Int64(2))) AS c1, starts_with(CAST(test.column1_large_utf8 AS Utf8View), substr(test.column1_large_utf8, Int64(1), Int64(2))) AS c2, starts_with(test.column1_utf8view, substr(test.column1_utf8view, Int64(1), Int64(2))) AS c3
02)--TableScan: test projection=[column1_utf8, column1_large_utf8, column1_utf8view]

query BBB