This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 13c174df4b6 branch-2.1: [fix](Nereids) fix substring with only one
parameter #48957 (#49030)
13c174df4b6 is described below
commit 13c174df4b6d0fcc0395f68467456cdf0d28b1cb
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Mar 19 09:56:13 2025 +0800
branch-2.1: [fix](Nereids) fix substring with only one parameter #48957
(#49030)
Cherry-picked from #48957
Co-authored-by: LiBinfeng <[email protected]>
---
.../trees/expressions/functions/executable/StringArithmetic.java | 7 ++++---
.../fold_constant/fold_constant_string_arithmatic.groovy | 6 ++++++
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java
index bc3317ea8d7..00b674ace6a 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java
@@ -84,7 +84,7 @@ public class StringArithmetic {
if (stringLength == 0) {
return "";
}
- int leftIndex = 0;
+ long leftIndex = 0;
if (second < (- stringLength)) {
return "";
} else if (second < 0) {
@@ -94,7 +94,7 @@ public class StringArithmetic {
} else {
return "";
}
- int rightIndex = 0;
+ long rightIndex = 0;
if (third <= 0) {
return "";
} else if ((third + leftIndex) > stringLength) {
@@ -102,7 +102,8 @@ public class StringArithmetic {
} else {
rightIndex = third + leftIndex;
}
- return first.substring(leftIndex, rightIndex);
+ // left index and right index are in integer range because of
definition, so we can safely cast it to int
+ return first.substring((int) leftIndex, (int) rightIndex);
}
/**
diff --git
a/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_string_arithmatic.groovy
b/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_string_arithmatic.groovy
index 734094eab86..dce90006065 100644
---
a/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_string_arithmatic.groovy
+++
b/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_string_arithmatic.groovy
@@ -653,6 +653,9 @@ suite("fold_constant_string_arithmatic") {
testFoldConst("select substr('abcdef',3,-1)")
testFoldConst("select substr('',3,-1)")
testFoldConst("select substr('abcdef',3,10)")
+ testFoldConst("select substr('abcdef',-3)")
+ testFoldConst("select substr('abcdef',3)")
+ testFoldConst("select substr('',3)")
// substring
testFoldConst("select substring('1', 1, 1)")
@@ -679,6 +682,9 @@ suite("fold_constant_string_arithmatic") {
testFoldConst("select substring('Hello World', 1, 5)")
testFoldConst("select substring('', 1, 5)")
testFoldConst("select substring('Hello World', 1, 50)")
+ testFoldConst("select substring('abcdef',-3)")
+ testFoldConst("select substring('abcdef',3)")
+ testFoldConst("select substring('',3)")
// substring_index
testFoldConst("select substring_index('a,b,c', ',', 2)")
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]