Jimexist commented on a change in pull request #1660:
URL: https://github.com/apache/arrow-datafusion/pull/1660#discussion_r791868982
##########
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:
```suggestion
0_usize.max(end_pos as usize),
```
--
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]