From cb217f711f0f60a299697ba3ee034a6caafbc330 Mon Sep 17 00:00:00 2001 From: LiBinfeng Date: Tue, 11 Mar 2025 14:31:09 +0800 Subject: [PATCH] [fix](Nereids) fix split part with delim not exist in source string (#48895) ### What problem does this PR solve? Related PR: #40441 Problem Summary: if source string do not contains delim, split_part should return NULL --- .../expressions/functions/executable/StringArithmetic.java | 3 +++ .../fold_constant/fold_constant_string_arithmatic.groovy | 3 +++ 2 files changed, 6 insertions(+) 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 18ec333882cc1e..f3cf756061acb9 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 @@ -699,6 +699,9 @@ public static Expression splitPart(StringLikeLiteral first, StringLikeLiteral ch return new NullLiteral(first.getDataType()); } } + if (!first.getValue().contains(chr.getValue())) { + return new NullLiteral(first.getDataType()); + } String separator = chr.getValue(); String[] parts; if (number.getValue() < 0) { 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 c046a0a0f8dc96..eb164356f9cdbd 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 @@ -592,6 +592,9 @@ suite("fold_constant_string_arithmatic") { testFoldConst("SELECT split_part('a..b\$\$c||d((e))f[[g{{h^^i??j**k++l\\\\m','**', 2)") testFoldConst("SELECT split_part('a..b\$\$c||d((e))f[[g{{h^^i??j**k++l\\\\m','++', 2)") testFoldConst("SELECT split_part('a..b\$\$c||d((e))f[[g{{h^^i??j**k++l\\\\m','\\\\', 2)") + testFoldConst("select split_part('abc', ':', -1)") + testFoldConst("select split_part('abc', ':', 0)") + testFoldConst("select split_part('abc', ':', 1)") // starts_with testFoldConst("select starts_with('hello world','hello')")