You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/01/31 20:11:36 UTC

[GitHub] [arrow-datafusion] alamb commented on a change in pull request #1660: fix: substr - correct behaivour with negative start pos

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



##########
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:
       @ovr  would you like to make this change so we can merge the PR? I can find some time to do so too if that would help.




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org