ovr commented on a change in pull request #1660:
URL: https://github.com/apache/arrow-datafusion/pull/1660#discussion_r796034327



##########
File path: datafusion/src/physical_plan/unicode_expressions.rs
##########
@@ -457,21 +457,29 @@ pub fn substr<T: StringOffsetSizeTrait>(args: 
&[ArrayRef]) -> Result<ArrayRef> {
                                 start,
                                 count
                             )))
-                        } else if start <= 0 {
-                            Ok(Some(string.to_string()))
                         } else {
                             let graphemes = 
string.graphemes(true).collect::<Vec<&str>>();
-                            let start_pos = start as usize - 1;
-                            let count_usize = count as usize;
-                            if graphemes.len() < start_pos {
+                            let (start_pos, end_pos) = if start <= 0 {
+                                let end_pos = start + count - 1;
+                                (
+                                    0_usize,
+                                    if end_pos < 0 {
+                                        // we use 0 as workaround for usize to 
return empty string
+                                        0
+                                    } else {
+                                        end_pos as usize
+                                    },

Review comment:
       @Jimexist It doesn't work because it doesn't reflect comparing with less 
than 0. `-1 (i32)` with `as usize` will produce a maximum number that can be 
stored in `usize`.
   
   
![image](https://user-images.githubusercontent.com/572096/151866702-28829160-8521-4129-a816-668196d4564a.png)
   
   @alamb It doesnt work.




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


Reply via email to