Skip to content

Commit

Permalink
[Bug] Fix locate bug when start_pos larger than str len (apache#4975)
Browse files Browse the repository at this point in the history
```
select locate('', 'abc', 10); 
```
Return 0 not 10
  • Loading branch information
chaoyli authored Nov 29, 2020
1 parent d7225d6 commit bb36de5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions be/src/exprs/string_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,15 @@ IntVal StringFunctions::locate_pos(FunctionContext* context, const StringVal& su
return IntVal::null();
}
if (substr.len == 0) {
if (str.len == 0 && start_pos.val > 1) {
if (start_pos.val <= 0) {
return IntVal(0);
} else if (start_pos.val == 1) {
return IntVal(1);
} else if (start_pos.val > str.len) {
return IntVal(0);
} else {
return IntVal(start_pos.val);
}
return IntVal(start_pos.val);
}
// Hive returns 0 for *start_pos <= 0,
// but throws an exception for *start_pos > str->len.
Expand Down

0 comments on commit bb36de5

Please sign in to comment.