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 7b37ca51c53fa4..49338d8edac12e 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 @@ -695,7 +695,7 @@ public static Expression splitPart(StringLikeLiteral first, StringLikeLiteral ch */ @ExecFunction(name = "substring_index") public static Expression substringIndex(StringLikeLiteral first, StringLikeLiteral chr, IntegerLiteral number) { - String[] parts = first.getValue().split(chr.getValue()); + String[] parts = first.getValue().split(chr.getValue(), -1); if (Math.abs(number.getValue()) >= parts.length) { return first; } 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 545ac19576be99..1ee02cea603341 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 @@ -774,5 +774,27 @@ suite("fold_constant_string_arithmatic") { testFoldConst("select append_trailing_char_if_absent('hello', ' ')") // Expected Output: 'hello ' + testFoldConst("SELECT SUBSTRING_INDEX('哈哈哈AAA','A', -5)") + testFoldConst("SELECT SUBSTRING_INDEX('哈哈哈AAA','A', -4)") + testFoldConst("SELECT SUBSTRING_INDEX('哈哈哈AAA','A', -3)") + testFoldConst("SELECT SUBSTRING_INDEX('哈哈哈AAA','A', -2)") + testFoldConst("SELECT SUBSTRING_INDEX('哈哈哈AAA','A', -1)") + testFoldConst("SELECT SUBSTRING_INDEX('哈哈哈AAA','A', 0)") + testFoldConst("SELECT SUBSTRING_INDEX('哈哈哈AAA','A', 1)") + testFoldConst("SELECT SUBSTRING_INDEX('哈哈哈AAA','A', 2)") + testFoldConst("SELECT SUBSTRING_INDEX('哈哈哈AAA','A', 3)") + testFoldConst("SELECT SUBSTRING_INDEX('哈哈哈AAA','A', 4)") + testFoldConst("SELECT SUBSTRING_INDEX('哈哈哈AAA','A', 5)") + testFoldConst("SELECT SUBSTRING_INDEX('哈哈哈AA+','A', -4)") + testFoldConst("SELECT SUBSTRING_INDEX('哈哈哈AA+','A', -3)") + testFoldConst("SELECT SUBSTRING_INDEX('哈哈哈AA+','A', -2)") + testFoldConst("SELECT SUBSTRING_INDEX('哈哈哈AA+','A', -1)") + testFoldConst("SELECT SUBSTRING_INDEX('哈哈哈AA+','A', 0)") + testFoldConst("SELECT SUBSTRING_INDEX('哈哈哈AA+','A', 1)") + testFoldConst("SELECT SUBSTRING_INDEX('哈哈哈AA+','A', 2)") + testFoldConst("SELECT SUBSTRING_INDEX('哈哈哈AA+','A', 3)") + testFoldConst("SELECT SUBSTRING_INDEX('哈哈哈AA+','A', 4)") + + }