Jefffrey commented on code in PR #20624:
URL: https://github.com/apache/datafusion/pull/20624#discussion_r2872506459
##########
datafusion/functions/src/unicode/translate.rs:
##########
@@ -172,41 +186,83 @@ fn try_as_scalar_str(cv: &ColumnarValue) -> Option<&str> {
}
fn invoke_translate(args: &[ArrayRef]) -> Result<ArrayRef> {
+ let len = args[0].len();
match args[0].data_type() {
DataType::Utf8View => {
let string_array = args[0].as_string_view();
let from_array = args[1].as_string::<i32>();
let to_array = args[2].as_string::<i32>();
- translate::<i32, _, _>(string_array, from_array, to_array)
+ let builder = StringViewBuilder::with_capacity(len);
+ translate(string_array, from_array, to_array, builder)
}
DataType::Utf8 => {
let string_array = args[0].as_string::<i32>();
let from_array = args[1].as_string::<i32>();
let to_array = args[2].as_string::<i32>();
- translate::<i32, _, _>(string_array, from_array, to_array)
+ let builder = GenericStringBuilder::<i32>::with_capacity(len, len
* 4);
+ translate(string_array, from_array, to_array, builder)
}
DataType::LargeUtf8 => {
let string_array = args[0].as_string::<i64>();
let from_array = args[1].as_string::<i32>();
let to_array = args[2].as_string::<i32>();
- translate::<i64, _, _>(string_array, from_array, to_array)
+ let builder = GenericStringBuilder::<i64>::with_capacity(len, len
* 4);
+ translate(string_array, from_array, to_array, builder)
}
other => {
exec_err!("Unsupported data type {other:?} for function translate")
}
}
}
+/// Helper trait to abstract over different string builder types so `translate`
+/// and `translate_with_map` can produce the correct output array type.
+trait TranslateOutput {
Review Comment:
Actually looks like we have
- https://docs.rs/arrow/latest/arrow/array/trait.StringLikeArrayBuilder.html
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]