-
Notifications
You must be signed in to change notification settings - Fork 0
20278: perf: Optimize lpad, rpad for ASCII strings #242
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,7 +15,10 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // specific language governing permissions and limitations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // under the License. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use arrow::array::{ArrowPrimitiveType, OffsetSizeTrait, PrimitiveArray}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use arrow::array::{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ArrowPrimitiveType, GenericStringBuilder, OffsetSizeTrait, PrimitiveArray, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| StringViewBuilder, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use arrow::datatypes::{DataType, Field, Int64Type}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use arrow::util::bench_util::{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create_string_array_with_len, create_string_view_array_with_len, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -30,6 +33,51 @@ use std::hint::black_box; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use std::sync::Arc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use std::time::Duration; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const UNICODE_STRINGS: &[&str] = &[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Ñandú", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Íslensku", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Þjóðarinnar", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Ελληνική", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Иванович", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "データフュージョン", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "José García", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Ölçü bïrïmï", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Ÿéšṱëṟḏàÿ", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Ährenstraße", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn create_unicode_string_array<O: OffsetSizeTrait>( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| size: usize, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| null_density: f32, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> arrow::array::GenericStringArray<O> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut rng = rand::rng(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut builder = GenericStringBuilder::<O>::new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for i in 0..size { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if rng.random::<f32>() < null_density { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| builder.append_null(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| builder.append_value(UNICODE_STRINGS[i % UNICODE_STRINGS.len()]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| builder.finish() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn create_unicode_string_view_array( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| size: usize, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| null_density: f32, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> arrow::array::StringViewArray { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut rng = rand::rng(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut builder = StringViewBuilder::with_capacity(size); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for i in 0..size { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if rng.random::<f32>() < null_density { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| builder.append_null(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| builder.append_value(UNICODE_STRINGS[i % UNICODE_STRINGS.len()]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| builder.finish() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| struct Filter<Dist> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dist: Dist, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -67,6 +115,34 @@ where | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .collect() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Create args for pad benchmark with Unicode strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn create_unicode_pad_args( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| size: usize, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target_len: usize, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use_string_view: bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> Vec<ColumnarValue> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let length_array = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Arc::new(create_primitive_array::<Int64Type>(size, 0.0, target_len)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if use_string_view { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let string_array = create_unicode_string_view_array(size, 0.1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let fill_array = create_unicode_string_view_array(size, 0.1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vec![ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ColumnarValue::Array(Arc::new(string_array)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ColumnarValue::Array(length_array), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ColumnarValue::Array(Arc::new(fill_array)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let string_array = create_unicode_string_array::<i32>(size, 0.1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let fill_array = create_unicode_string_array::<i32>(size, 0.1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vec![ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ColumnarValue::Array(Arc::new(string_array)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ColumnarValue::Array(length_array), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ColumnarValue::Array(Arc::new(fill_array)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+127
to
+143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value:good-to-have; category:bug; feedback: The Gemini AI reviewer is correct! The logic for constructing the ColumnarValues could be simplified. it will be both easier to maintain and it will be more performant. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Create args for pad benchmark | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn create_pad_args<O: OffsetSizeTrait>( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| size: usize, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -208,6 +284,58 @@ fn criterion_benchmark(c: &mut Criterion) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Utf8 type with Unicode strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let args = create_unicode_pad_args(size, 20, false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let arg_fields = args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .iter() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .enumerate() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .map(|(idx, arg)| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Field::new(format!("arg_{idx}"), arg.data_type(), true).into() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .collect::<Vec<_>>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| group.bench_function( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| format!("lpad utf8 unicode [size={size}, target=20]"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |b| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b.iter(|| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let args_cloned = args.clone(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| black_box(unicode::lpad().invoke_with_args(ScalarFunctionArgs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| args: args_cloned, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| arg_fields: arg_fields.clone(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| number_rows: size, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return_field: Field::new("f", DataType::Utf8, true).into(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| config_options: Arc::clone(&config_options), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| })) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // StringView type with Unicode strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let args = create_unicode_pad_args(size, 20, true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let arg_fields = args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .iter() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .enumerate() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .map(|(idx, arg)| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Field::new(format!("arg_{idx}"), arg.data_type(), true).into() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .collect::<Vec<_>>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| group.bench_function( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| format!("lpad stringview unicode [size={size}, target=20]"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |b| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b.iter(|| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let args_cloned = args.clone(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| black_box(unicode::lpad().invoke_with_args(ScalarFunctionArgs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| args: args_cloned, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| arg_fields: arg_fields.clone(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| number_rows: size, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return_field: Field::new("f", DataType::Utf8View, true).into(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| config_options: Arc::clone(&config_options), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| })) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| group.finish(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -322,6 +450,58 @@ fn criterion_benchmark(c: &mut Criterion) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Utf8 type with Unicode strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let args = create_unicode_pad_args(size, 20, false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let arg_fields = args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .iter() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .enumerate() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .map(|(idx, arg)| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Field::new(format!("arg_{idx}"), arg.data_type(), true).into() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .collect::<Vec<_>>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| group.bench_function( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| format!("rpad utf8 unicode [size={size}, target=20]"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |b| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b.iter(|| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let args_cloned = args.clone(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| black_box(unicode::rpad().invoke_with_args(ScalarFunctionArgs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| args: args_cloned, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| arg_fields: arg_fields.clone(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| number_rows: size, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return_field: Field::new("f", DataType::Utf8, true).into(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| config_options: Arc::clone(&config_options), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| })) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // StringView type with Unicode strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let args = create_unicode_pad_args(size, 20, true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let arg_fields = args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .iter() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .enumerate() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .map(|(idx, arg)| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Field::new(format!("arg_{idx}"), arg.data_type(), true).into() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .collect::<Vec<_>>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| group.bench_function( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| format!("rpad stringview unicode [size={size}, target=20]"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |b| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b.iter(|| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let args_cloned = args.clone(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| black_box(unicode::rpad().invoke_with_args(ScalarFunctionArgs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| args: args_cloned, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| arg_fields: arg_fields.clone(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| number_rows: size, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return_field: Field::new("f", DataType::Utf8View, true).into(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| config_options: Arc::clone(&config_options), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| })) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| group.finish(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's significant code duplication between
create_unicode_string_arrayandcreate_unicode_string_view_array. The logic inside both functions is nearly identical. Consider refactoring this to a single generic function or a macro to reduce duplication and improve maintainability.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value:good-to-have; category:bug; feedback: The Gemini AI reviewer is correct! The two functions are almost identical and they could be merged into a single more generic one and reused.