This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 5dd341edddc [bugfix](nerids) complete the implementation of the concat 
method. (#51141)
5dd341edddc is described below

commit 5dd341edddc36d5e4ffb617019f2170cc57403bc
Author: XLPE <[email protected]>
AuthorDate: Mon May 26 10:01:50 2025 +0800

    [bugfix](nerids) complete the implementation of the concat method. (#51141)
    
    Problem Summary:
    In Doris versions above 2.1.8 and above 3.0.3, , the newly added concat
    function can't fold when more than two parameters.
    before:
    ```
    mysql> EXPLAIN SELECT concat('a', 'a', 'b', 'c', 'd', 'efddd');
    +---------------------------------------------------+
    | Explain String(Nereids Planner)                   |
    +---------------------------------------------------+
    | PLAN FRAGMENT 0                                   |
    |   OUTPUT EXPRS:                                   |
    |     concat('a', 'a', 'b', 'c', 'd', 'efddd')[#0]  |
    |   PARTITION: UNPARTITIONED                        |
    |                                                   |
    |   HAS_COLO_PLAN_NODE: false                       |
    |                                                   |
    |   VRESULT SINK                                    |
    |      MYSQL_PROTOCAL                               |
    |                                                   |
    |   0:VUNION(30)                                    |
    |      constant exprs:                              |
    |          concat('a', 'a', 'b', 'c', 'd', 'efddd') |
    +---------------------------------------------------+
    ```
    after:
    ```
    mysql> EXPLAIN SELECT concat('a', 'a', 'b', 'c', 'd', 'efddd');
    +----------------------------------+
    | Explain String(Nereids Planner)  |
    +----------------------------------+
    | PLAN FRAGMENT 0                  |
    |   OUTPUT EXPRS:                  |
    |     'aabcdefddd'[#0]             |
    |   PARTITION: UNPARTITIONED       |
    |                                  |
    |   HAS_COLO_PLAN_NODE: false      |
    |                                  |
    |   VRESULT SINK                   |
    |      MYSQL_PROTOCAL              |
    |                                  |
    |   0:VUNION(30)                   |
    |      constant exprs:             |
    |          'aabcdefddd'            |
    +----------------------------------+
    ```
    
    
    Co-authored-by: weiwh1 <[email protected]>
---
 .../trees/expressions/functions/executable/StringArithmetic.java | 9 ++++++---
 .../test/java/org/apache/doris/catalog/CreateFunctionTest.java   | 4 ++--
 2 files changed, 8 insertions(+), 5 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 221208dc9eb..f0336caa5e4 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
@@ -74,9 +74,12 @@ public class StringArithmetic {
      * Executable arithmetic functions concat
      */
     @ExecFunction(name = "concat")
-    public static Expression concatVarcharVarchar(StringLikeLiteral first, 
StringLikeLiteral second) {
-        String result = first.getValue() + second.getValue();
-        return castStringLikeLiteral(first, result);
+    public static Expression concatVarchar(StringLikeLiteral... values) {
+        final StringBuilder sb = new StringBuilder();
+        for (StringLikeLiteral value : values) {
+            sb.append(value.getValue());
+        }
+        return castStringLikeLiteral(values[0], sb.toString());
     }
 
     private static String substringImpl(String first, int second, int third) {
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java
index 33c0c8f2882..d142134ddcd 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java
@@ -107,7 +107,7 @@ public class CreateFunctionTest {
         List<List<Expr>> constExprLists = Deencapsulation.getField(unionNode, 
"constExprLists");
         Assert.assertEquals(1, constExprLists.size());
         Assert.assertEquals(1, constExprLists.get(0).size());
-        Assert.assertTrue(constExprLists.get(0).get(0) instanceof 
FunctionCallExpr);
+        Assert.assertTrue(constExprLists.get(0).get(0) instanceof 
StringLiteral);
 
         queryStr = "select db1.id_masking(k1) from db1.tbl1";
         
Assert.assertTrue(containsIgnoreCase(dorisAssert.query(queryStr).explainQuery(),
@@ -144,7 +144,7 @@ public class CreateFunctionTest {
         Assert.assertEquals(1, functions.size());
 
         String queryStr = "select id_masking(13888888888);";
-        testFunctionQuery(ctx, queryStr, false);
+        testFunctionQuery(ctx, queryStr, true);
 
         queryStr = "select id_masking(k1) from db2.tbl1";
         
Assert.assertTrue(containsIgnoreCase(dorisAssert.query(queryStr).explainQuery(),


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to