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

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

commit a8ba933947cb45fff9d6cdd86f5f6fc484463cbb
Author: feiniaofeiafei <53502832+feiniaofeia...@users.noreply.github.com>
AuthorDate: Fri Apr 19 10:43:26 2024 +0800

    [Fix](nereids) fix bind order by expression logic (#33843)
---
 .../nereids/rules/analysis/BindExpression.java     |  4 +--
 .../nereids_syntax_p0/order_by_bind_priority.out   | 22 +++++++++++++
 .../order_by_bind_priority.groovy                  | 36 ++++++++++++++++++++++
 3 files changed, 60 insertions(+), 2 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java
index 8957800c7ed..3c73a53dcba 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java
@@ -774,9 +774,9 @@ public class BindExpression implements AnalysisRuleFactory {
                 (self, unboundSlot) -> {
                     // first, try to bind slot in Scope(input.output)
                     List<Slot> slotsInInput = 
self.bindExactSlotsByThisScope(unboundSlot, inputScope);
-                    if (slotsInInput.size() == 1) {
+                    if (!slotsInInput.isEmpty()) {
                         // bind succeed
-                        return slotsInInput;
+                        return ImmutableList.of(slotsInInput.get(0));
                     }
                     // second, bind failed:
                     // if the slot not found, or more than one candidate slots 
found in input.output,
diff --git a/regression-test/data/nereids_syntax_p0/order_by_bind_priority.out 
b/regression-test/data/nereids_syntax_p0/order_by_bind_priority.out
index 3c7dcb1d318..4fd63bc7f99 100644
--- a/regression-test/data/nereids_syntax_p0/order_by_bind_priority.out
+++ b/regression-test/data/nereids_syntax_p0/order_by_bind_priority.out
@@ -23,3 +23,25 @@
 3      3
 5      5
 
+-- !test_multi_slots_in_agg_func_bind_first --
+\N     -3      2       \N      \N      \N
+\N     0       5       \N      16155   16155
+\N     1       6       \N      \N      \N
+\N     2       7       \N      \N      \N
+\N     6       11      \N      \N      \N
+\N     8       13      \N      \N      \N
+\N     13      18      \N      \N      \N
+2      -5      0       8777    \N      \N
+2      -4      1       127     30240   30240
+2      -2      3       10008   -54     -54
+2      3       8       29433   -4654   -4654
+2      4       9       13909   29600   29600
+2      12      17      22950   99      99
+4      -1      4       3618    2881    2881
+4      5       10      10450   8105    8105
+4      7       12      88      88      88
+4      9       14      74      14138   14138
+4      10      15      23      63      63
+4      11      16      4418    -24598  -24598
+4      14      19      2       \N      \N
+
diff --git 
a/regression-test/suites/nereids_syntax_p0/order_by_bind_priority.groovy 
b/regression-test/suites/nereids_syntax_p0/order_by_bind_priority.groovy
index e434ab42092..44c8b5fa734 100644
--- a/regression-test/suites/nereids_syntax_p0/order_by_bind_priority.groovy
+++ b/regression-test/suites/nereids_syntax_p0/order_by_bind_priority.groovy
@@ -33,6 +33,42 @@ suite("order_by_bind_priority") {
         sql "select abs(sum(c1)) as c1, c1,sum(c2) as c2 from 
t_order_by_bind_priority group by c1 order by sum(c1)+c2 asc;"
         exception "c2 should be grouped by."
     }
+    sql """drop table if exists 
table_20_undef_partitions2_keys3_properties4_distributed_by58"""
+    sql """
+        create table 
table_20_undef_partitions2_keys3_properties4_distributed_by58 (
+        pk int,
+        col_int_undef_signed int   ,
+        col_int_undef_signed2 int
+        ) engine=olap
+        DUPLICATE KEY(pk, col_int_undef_signed)
+        distributed by hash(pk) buckets 10
+        properties("replication_num" = "1");
+    """
+    sql """
+        insert into 
table_20_undef_partitions2_keys3_properties4_distributed_by58(pk,col_int_undef_signed,col_int_undef_signed2)
 values (0,-8777,null),
+        
(1,-127,30240),(2,null,null),(3,-10008,-54),(4,3618,2881),(5,null,16155),(6,null,null),(7,null,null),(8,-29433,-4654),(9,-13909,29600),(10,10450,8105),
+        
(11,null,null),(12,88,88),(13,null,null),(14,74,14138),(15,23,63),(16,4418,-24598),(17,-22950,99),(18,null,null),(19,2,null);
+    """
+    sql "sync;"
 
+    qt_test_multi_slots_in_agg_func_bind_first """
+        SELECT
+        SIGN( SUM(col_int_undef_signed) ) + 3 AS col_int_undef_signed,
+        pk - 5 pk ,
+        pk pk ,
+        ABS( MIN(col_int_undef_signed) ) AS col_int_undef_signed,
+        MAX(col_int_undef_signed2) col_int_undef_signed2,
+        col_int_undef_signed2 col_int_undef_signed2
+        FROM
+        table_20_undef_partitions2_keys3_properties4_distributed_by58 
tbl_alias1
+        GROUP BY
+        pk,
+        col_int_undef_signed2
+        ORDER BY
+        col_int_undef_signed,
+        pk - 5,
+        pk,
+        col_int_undef_signed2 ;
+    """
 
 }
\ No newline at end of file


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

Reply via email to