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 4e1cdb9ce7 [fix](agg_sort)fix bug of agg sort group concat with order 
by(#18447)
4e1cdb9ce7 is described below

commit 4e1cdb9ce7e5ab42b8be6b00d51f3d988caa320c
Author: TengJianPing <[email protected]>
AuthorDate: Fri Apr 7 08:42:36 2023 +0800

    [fix](agg_sort)fix bug of agg sort group concat with order by(#18447)
---
 be/src/vec/exprs/vectorized_agg_fn.cpp             |  4 +--
 .../nereids_p0/group_concat/test_group_concat.out  | 24 +++++++++++++++++
 .../query_p0/group_concat/test_group_concat.out    | 25 ++++++++++++++++--
 .../group_concat/test_group_concat.groovy          | 30 ++++++++++++++++++++++
 .../query_p0/group_concat/test_group_concat.groovy | 30 ++++++++++++++++++++++
 5 files changed, 109 insertions(+), 4 deletions(-)

diff --git a/be/src/vec/exprs/vectorized_agg_fn.cpp 
b/be/src/vec/exprs/vectorized_agg_fn.cpp
index 5c5ed94d17..555ce77f0f 100644
--- a/be/src/vec/exprs/vectorized_agg_fn.cpp
+++ b/be/src/vec/exprs/vectorized_agg_fn.cpp
@@ -73,8 +73,8 @@ Status AggFnEvaluator::create(ObjectPool* pool, const TExpr& 
desc, const TSortIn
     // to the order by functions
     for (int i = 0; i < sort_size; ++i) {
         agg_fn_evaluator->_sort_description.emplace_back(real_arguments_size + 
i,
-                                                         
sort_info.is_asc_order[i] == true,
-                                                         
sort_info.nulls_first[i] == true);
+                                                         
sort_info.is_asc_order[i] ? 1 : -1,
+                                                         
sort_info.nulls_first[i] ? -1 : 1);
     }
 
     // Pass the real arguments to get functions
diff --git a/regression-test/data/nereids_p0/group_concat/test_group_concat.out 
b/regression-test/data/nereids_p0/group_concat/test_group_concat.out
index c00188a6cf..157046ae1e 100644
--- a/regression-test/data/nereids_p0/group_concat/test_group_concat.out
+++ b/regression-test/data/nereids_p0/group_concat/test_group_concat.out
@@ -35,3 +35,27 @@ false
 1      2
 1      2
 
+-- !select_group_concat_order_by_all_data --
+1      1       1
+1      1       11
+1      2       2
+1      2       21
+1      3       3
+2      21      21
+2      21      211
+2      22      22
+2      22      222
+2      23      23
+
+-- !select_group_concat_order_by_desc1 --
+1      3, 2, 2, 1, 1
+2      23, 22, 22, 21, 21
+
+-- !select_group_concat_order_by_desc2 --
+1      3, 2, 21, 1, 11
+2      23, 22, 222, 21, 211
+
+-- !select_group_concat_order_by_desc3 --
+1      3, 21, 2, 11, 1
+2      23, 222, 22, 211, 21
+
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 2b121d104f..157046ae1e 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
@@ -35,6 +35,27 @@ false
 1      2
 1      2
 
--- !select_11 --
-1      2
+-- !select_group_concat_order_by_all_data --
+1      1       1
+1      1       11
+1      2       2
+1      2       21
+1      3       3
+2      21      21
+2      21      211
+2      22      22
+2      22      222
+2      23      23
+
+-- !select_group_concat_order_by_desc1 --
+1      3, 2, 2, 1, 1
+2      23, 22, 22, 21, 21
+
+-- !select_group_concat_order_by_desc2 --
+1      3, 2, 21, 1, 11
+2      23, 22, 222, 21, 211
+
+-- !select_group_concat_order_by_desc3 --
+1      3, 21, 2, 11, 1
+2      23, 222, 22, 211, 21
 
diff --git 
a/regression-test/suites/nereids_p0/group_concat/test_group_concat.groovy 
b/regression-test/suites/nereids_p0/group_concat/test_group_concat.groovy
index 242da3453a..e8da38db86 100644
--- a/regression-test/suites/nereids_p0/group_concat/test_group_concat.groovy
+++ b/regression-test/suites/nereids_p0/group_concat/test_group_concat.groovy
@@ -83,4 +83,34 @@ suite("test_group_concat") {
                 group by 
                 b2;
               """
+
+    sql """ drop table table_group_concat """
+    sql """create table table_group_concat ( b1 varchar(10) not null, b2 int 
not null, b3 varchar(10) not null )
+            ENGINE=OLAP
+            DISTRIBUTED BY HASH(b3) BUCKETS 4
+            PROPERTIES (
+            "replication_allocation" = "tag.location.default: 1",
+            "in_memory" = "false",
+            "storage_format" = "V2"
+            );
+        """
+
+    sql """insert into table_group_concat values('1', 1, '1'),('1', 2, 
'2'),('1', 3, '3');"""
+    sql """insert into table_group_concat values('1', 1, '11'),('1', 2, 
'21');"""
+    sql """insert into table_group_concat values('2', 21, '21'),('2', 22, 
'22'),('2', 23, '23');"""
+    sql """insert into table_group_concat values('2', 21, '211'),('2', 22, 
'222');"""
+
+    qt_select_group_concat_order_by_all_data """
+      select * from table_group_concat order by b1, b2, b3;
+    """
+    qt_select_group_concat_order_by_desc1 """
+                SELECT b1, group_concat(cast(abs(b2) as varchar) order by 
abs(b2) desc) FROM table_group_concat  group by b1 order by b1
+              """
+
+    qt_select_group_concat_order_by_desc2 """
+                SELECT b1, group_concat(cast(abs(b3) as varchar) order by 
abs(b2) desc, b3) FROM table_group_concat  group by b1 order by b1
+              """
+    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
+              """
 }
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 8b2739af0f..5179114950 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
@@ -80,4 +80,34 @@ suite("test_group_concat") {
                 group by 
                 b2;
               """
+
+    sql """ drop table table_group_concat """
+    sql """create table table_group_concat ( b1 varchar(10) not null, b2 int 
not null, b3 varchar(10) not null )
+            ENGINE=OLAP
+            DISTRIBUTED BY HASH(b3) BUCKETS 4
+            PROPERTIES (
+            "replication_allocation" = "tag.location.default: 1",
+            "in_memory" = "false",
+            "storage_format" = "V2"
+            );
+        """
+
+    sql """insert into table_group_concat values('1', 1, '1'),('1', 2, 
'2'),('1', 3, '3');"""
+    sql """insert into table_group_concat values('1', 1, '11'),('1', 2, 
'21');"""
+    sql """insert into table_group_concat values('2', 21, '21'),('2', 22, 
'22'),('2', 23, '23');"""
+    sql """insert into table_group_concat values('2', 21, '211'),('2', 22, 
'222');"""
+
+    qt_select_group_concat_order_by_all_data """
+      select * from table_group_concat order by b1, b2, b3;
+    """
+    qt_select_group_concat_order_by_desc1 """
+                SELECT b1, group_concat(cast(abs(b2) as varchar) order by 
abs(b2) desc) FROM table_group_concat  group by b1 order by b1
+              """
+
+    qt_select_group_concat_order_by_desc2 """
+                SELECT b1, group_concat(cast(abs(b3) as varchar) order by 
abs(b2) desc, b3) FROM table_group_concat  group by b1 order by b1
+              """
+    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
+              """
 }


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

Reply via email to