[Bug] Fix locate bug when start_pos larger than str len (#4975)

```
select locate('', 'abc', 10); 
```
Return 0 not 10
This commit is contained in:
lichaoyong
2020-11-29 10:38:30 +08:00
committed by GitHub
parent d7225d61ef
commit bb36de52a6

View File

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