This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push:
new baff13ef466 branch-3.0: [fix](Nereids) fix substring with only one
parameter #48957 (#49029)
baff13ef466 is described below
commit baff13ef4667e03c43cf5652a7c2573bc50d1776
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Sat Mar 15 10:11:00 2025 +0800
branch-3.0: [fix](Nereids) fix substring with only one parameter #48957
(#49029)
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 18ec333882c..799bbb7585c 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
@@ -83,7 +83,7 @@ public class StringArithmetic {
if (stringLength == 0) {
return "";
}
- int leftIndex = 0;
+ long leftIndex = 0;
if (second < (- stringLength)) {
return "";
} else if (second < 0) {
@@ -93,7 +93,7 @@ public class StringArithmetic {
} else {
return "";
}
- int rightIndex = 0;
+ long rightIndex = 0;
if (third <= 0) {
return "";
} else if ((third + leftIndex) > stringLength) {
@@ -101,7 +101,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 c046a0a0f8d..74e5b60bff6 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
@@ -660,6 +660,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)")
@@ -686,6 +689,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]