Jefffrey commented on code in PR #20624:
URL: https://github.com/apache/datafusion/pull/20624#discussion_r2872229035


##########
datafusion/functions/src/unicode/translate.rs:
##########
@@ -93,7 +94,11 @@ impl ScalarUDFImpl for TranslateFunc {
     }
 
     fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
-        utf8_to_str_type(&arg_types[0], "translate")
+        if arg_types[0] == DataType::Utf8View {
+            Ok(DataType::Utf8View)
+        } else {
+            utf8_to_str_type(&arg_types[0], "translate")
+        }

Review Comment:
   ```suggestion
           Ok(arg_types[0].clone())
   ```
   
   Simpler



##########
datafusion/functions/src/unicode/translate.rs:
##########
@@ -116,33 +121,42 @@ impl ScalarUDFImpl for TranslateFunc {
             let ascii_table = build_ascii_translate_table(from_str, to_str);
 
             let string_array = 
args.args[0].to_array_of_size(args.number_rows)?;
+            let len = string_array.len();
 
             let result = match string_array.data_type() {
                 DataType::Utf8View => {
                     let arr = string_array.as_string_view();
-                    translate_with_map::<i32, _>(
+                    let builder = StringViewBuilder::with_capacity(len);
+                    translate_with_map(
                         arr,
                         &from_map,
                         &to_graphemes,
                         ascii_table.as_ref(),
+                        builder,
                     )
                 }
                 DataType::Utf8 => {
                     let arr = string_array.as_string::<i32>();
-                    translate_with_map::<i32, _>(
+                    let builder =
+                        GenericStringBuilder::<i32>::with_capacity(len, len * 
4);

Review Comment:
   Why `* 4`? Seems it might overestimate, compared to getting the byte size 
from input array?



-- 
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]

Reply via email to