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

panxiaolei 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 5788214416 [Bug](function) fix equals implements not judge order by 
elements of function call expr (#20083)
5788214416 is described below

commit 5788214416479871f4af92956d4b75dfa676ee79
Author: Pxl <pxl...@qq.com>
AuthorDate: Mon May 29 19:03:05 2023 +0800

    [Bug](function) fix equals implements not judge order by elements of 
function call expr (#20083)
    
    fix equals implements not judge order by elements of function call expr
    #19296
---
 .../apache/doris/analysis/FunctionCallExpr.java    | 31 ++++++++++++++++------
 .../query_p0/group_concat/test_group_concat.out    |  3 +++
 .../query_p0/group_concat/test_group_concat.groovy |  4 +++
 3 files changed, 30 insertions(+), 8 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
index a8551d5aa1..ec2884d0b6 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
@@ -508,6 +508,14 @@ public class FunctionCallExpr extends Expr {
             return false;
         }
         FunctionCallExpr o = (FunctionCallExpr) obj;
+        if (orderByElements.size() != o.orderByElements.size()) {
+            return false;
+        }
+        for (int i = 0; i < orderByElements.size(); i++) {
+            if (!orderByElements.get(i).equals(o.orderByElements.get(i))) {
+                return false;
+            }
+        }
         return /*opcode == o.opcode && aggOp == o.aggOp &&*/ 
fnName.equals(o.fnName)
                 && fnParams.isDistinct() == o.fnParams.isDistinct()
                 && fnParams.isStar() == o.fnParams.isStar();
@@ -524,10 +532,8 @@ public class FunctionCallExpr extends Expr {
             sb.append("DISTINCT ");
         }
         int len = children.size();
-        List<String> result = Lists.newArrayList();
         // XXX_diff are used by nereids only
-        if (fnName.getFunction().equalsIgnoreCase("years_diff")
-                || fnName.getFunction().equalsIgnoreCase("months_diff")
+        if (fnName.getFunction().equalsIgnoreCase("years_diff") || 
fnName.getFunction().equalsIgnoreCase("months_diff")
                 || fnName.getFunction().equalsIgnoreCase("days_diff")
                 || fnName.getFunction().equalsIgnoreCase("hours_diff")
                 || fnName.getFunction().equalsIgnoreCase("minutes_diff")
@@ -544,6 +550,9 @@ public class FunctionCallExpr extends Expr {
         }
 
         for (int i = 0; i < len; ++i) {
+            if (i != 0) {
+                sb.append(", ");
+            }
             if (ConnectContext.get() != null && 
ConnectContext.get().getState().isQuery() && i == 1
                     && (fnName.getFunction().equalsIgnoreCase("aes_decrypt")
                             || 
fnName.getFunction().equalsIgnoreCase("aes_encrypt")
@@ -553,14 +562,20 @@ public class FunctionCallExpr extends Expr {
                             || 
fnName.getFunction().equalsIgnoreCase("aes_encrypt_v2")
                             || 
fnName.getFunction().equalsIgnoreCase("sm4_decrypt_v2")
                             || 
fnName.getFunction().equalsIgnoreCase("sm4_encrypt_v2"))) {
-                result.add("\'***\'");
+                sb.append("\'***\'");
             } else if (orderByElements.size() > 0 && i == len - 
orderByElements.size()) {
-                result.add("ORDER BY " + children.get(i).toSql());
-            } else {
-                result.add(children.get(i).toSql());
+                sb.append("ORDER BY ");
+            }
+            sb.append(children.get(i).toSql());
+            if (orderByElements.size() > 0 && i >= len - 
orderByElements.size()) {
+                if (orderByElements.get(i - len + 
orderByElements.size()).getIsAsc()) {
+                    sb.append(" ASC");
+                } else {
+                    sb.append(" DESC");
+                }
             }
         }
-        sb.append(Joiner.on(", ").join(result)).append(")");
+        sb.append(")");
         return sb.toString();
     }
 
diff --git a/regression-test/data/query_p0/group_concat/test_group_concat.out 
b/regression-test/data/query_p0/group_concat/test_group_concat.out
index 157046ae1e..8fdcde8db4 100644
--- a/regression-test/data/query_p0/group_concat/test_group_concat.out
+++ b/regression-test/data/query_p0/group_concat/test_group_concat.out
@@ -59,3 +59,6 @@ false
 1      3, 21, 2, 11, 1
 2      23, 222, 22, 211, 21
 
+-- !select_group_concat_order_by --
+1,11,2,21,21,211,22,222,23,3   3,23,222,22,211,21,21,2,11,1
+
diff --git 
a/regression-test/suites/query_p0/group_concat/test_group_concat.groovy 
b/regression-test/suites/query_p0/group_concat/test_group_concat.groovy
index 5179114950..41069a2db8 100644
--- a/regression-test/suites/query_p0/group_concat/test_group_concat.groovy
+++ b/regression-test/suites/query_p0/group_concat/test_group_concat.groovy
@@ -110,4 +110,8 @@ suite("test_group_concat") {
     qt_select_group_concat_order_by_desc3 """
                 SELECT b1, group_concat(cast(abs(b3) as varchar) order by 
abs(b2) desc, b3 desc) FROM table_group_concat  group by b1 order by b1
               """
+    qt_select_group_concat_order_by """
+                select group_concat(b3,',' order by b3 
asc),group_concat(b3,',' order by b3 desc) from table_group_concat;
+    """
+
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to