XiangpengHao commented on code in PR #11955:
URL: https://github.com/apache/datafusion/pull/11955#discussion_r1714522453


##########
datafusion/functions/src/unicode/right.rs:
##########
@@ -83,6 +93,47 @@ impl ScalarUDFImpl for RightFunc {
 /// right('abcde', 2) = 'de'
 /// The implementation uses UTF-8 code points as characters
 pub fn right<T: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<ArrayRef> {
+    if args[0].data_type() == &DataType::Utf8View {
+        string_view_right(args)
+    } else {
+        string_right::<T>(args)
+    }
+}
+
+// Currently the return type can only be Utf8 or LargeUtf8, to reach fully 
support, we need
+// to edit the `get_optimal_return_type` in utils.rs to make the udfs be able 
to return Utf8View
+// See 
https://github.com/apache/datafusion/issues/11790#issuecomment-2283777166
+fn string_view_right(args: &[ArrayRef]) -> Result<ArrayRef> {
+    let string_array = as_string_view_array(&args[0])?;
+    let n_array = as_int64_array(&args[1])?;
+
+    let result = string_array

Review Comment:
   Code below is quite similar to the `string_right` function, I wonder if it 
is possible to use the `ArrayAccessor` to reuse the code:
   
https://github.com/apache/arrow-rs/blob/a693f0f9c37567b2b121e261fc0a4587776d5ca4/arrow-array/src/array/mod.rs#L438-L531
   
   Similar to this pr: 
https://github.com/apache/datafusion/pull/11884/files#diff-e49633ca67d4035f244e96909aa4d9d9a484a933a7783bcdee3a6cf32dcd7ab8R76



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