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

morrysnow 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 1617368ee1 [fix](planner) fix bug of push constant conjuncts through 
set operation node (#22695)
1617368ee1 is described below

commit 1617368ee11e2ae27a0c9752888ff472a3763556
Author: starocean999 <40539150+starocean...@users.noreply.github.com>
AuthorDate: Tue Aug 8 12:25:42 2023 +0800

    [fix](planner) fix bug of push constant conjuncts through set operation 
node (#22695)
    
    when pushing down constant conjunct into set operation node, we should 
assign the conjunct to agg node if there is one. This is consistant with 
pushing constant conjunct into inlineview.
---
 .../apache/doris/planner/SingleNodePlanner.java    | 13 ++++-
 .../data/correctness_p0/test_distinct_agg.out      |  4 ++
 .../suites/correctness_p0/test_distinct_agg.groovy | 58 ++++++++++++++++++++--
 3 files changed, 69 insertions(+), 6 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java 
b/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java
index 7cc6ae7cd2..8cf889d995 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java
@@ -2374,7 +2374,18 @@ public class SingleNodePlanner {
                 // Forbid to register Conjuncts with SelectStmt' tuple when 
Select is constant
                 if ((queryStmt instanceof SelectStmt) && selectHasTableRef) {
                     final SelectStmt select = (SelectStmt) queryStmt;
-                    op.getAnalyzer().registerConjuncts(opConjuncts, 
select.getTableRefIds());
+                    // if there is an agg node, we need register the constant 
conjuncts on agg node's tuple
+                    // this is consistent with migrateConstantConjuncts()
+                    if (select.getAggInfo() != null) {
+                        Map<Boolean, List<Expr>> splittedConjuncts = 
opConjuncts.stream()
+                                .collect(Collectors.partitioningBy(expr -> 
expr.isConstant()));
+                        
op.getAnalyzer().registerConjuncts(splittedConjuncts.get(true),
+                                
select.getAggInfo().getOutputTupleId().asList());
+                        
op.getAnalyzer().registerConjuncts(splittedConjuncts.get(false),
+                                select.getTableRefIds());
+                    } else {
+                        op.getAnalyzer().registerConjuncts(opConjuncts, 
select.getTableRefIds());
+                    }
                 } else if (queryStmt instanceof SetOperationStmt) {
                     final SetOperationStmt subSetOp = (SetOperationStmt) 
queryStmt;
                     op.getAnalyzer().registerConjuncts(opConjuncts, 
subSetOp.getTupleId().asList());
diff --git a/regression-test/data/correctness_p0/test_distinct_agg.out 
b/regression-test/data/correctness_p0/test_distinct_agg.out
new file mode 100644
index 0000000000..b70da182ee
--- /dev/null
+++ b/regression-test/data/correctness_p0/test_distinct_agg.out
@@ -0,0 +1,4 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !select1 --
+本日
+
diff --git a/regression-test/suites/correctness_p0/test_distinct_agg.groovy 
b/regression-test/suites/correctness_p0/test_distinct_agg.groovy
index ea2cd1f4a4..788f5271a6 100644
--- a/regression-test/suites/correctness_p0/test_distinct_agg.groovy
+++ b/regression-test/suites/correctness_p0/test_distinct_agg.groovy
@@ -16,10 +16,10 @@
 // under the License.
 
 suite("test_distinct_agg") {
-    sql 'drop table if exists t'
+    sql 'drop table if exists test_distinct_agg_t'
 
     sql '''
-        CREATE TABLE `t` (
+        CREATE TABLE `test_distinct_agg_t` (
             `k1` bigint(20) NULL,
             `k2` varchar(20) NULL,
             `k3` varchar(20) NULL,
@@ -35,7 +35,7 @@ suite("test_distinct_agg") {
     '''
 
     sql '''
-        INSERT INTO `t` (`k1`, `k2`, `k3`, `k4`, `k5`, `k6`) VALUES
+        INSERT INTO `test_distinct_agg_t` (`k1`, `k2`, `k3`, `k4`, `k5`, `k6`) 
VALUES
             (1, '1234', 'A0', 'C0', '1', '2023-01-10 23:00:00');
     '''
 
@@ -47,7 +47,7 @@ suite("test_distinct_agg") {
                     k5,
                     date_format(k6, '%Y-%m-%d') as k6,
                     count(distinct k3) as k3 
-                from t 
+                from test_distinct_agg_t 
                 where 1=1 
                 group by k5, k6
             ) AS temp where 1=1
@@ -65,8 +65,56 @@ suite("test_distinct_agg") {
                     (SELECT `k6` AS `dt`,
                     `k1` AS `role_id`,
                     sum(CAST(`k2` AS INT)) AS `cost`
-                    FROM `t`
+                    FROM `test_distinct_agg_t`
                     GROUP BY  `dt`, `role_id`) a
                     GROUP BY  `dt`) b 
                 WHERE `dt` = '2023-06-18';'''
+
+    sql 'drop view if exists dim_v2'
+    sql '''create 
+        view `dim_v2` COMMENT 'VIEW' as
+        select
+        curdate() as `calday`,
+            '本日' as `date_tag`
+        from
+            `test_distinct_agg_t`
+        union all
+        select
+            distinct curdate() as `calday`
+            , '本年' as `date_tag`
+        from
+            `test_distinct_agg_t` t1
+        union all
+        select
+            distinct `t1`.`k1` as `calday`
+            , '上年' as `date_tag`
+        from
+            `test_distinct_agg_t` t1;'''
+
+    sql 'drop view if exists dim_v3'
+    sql '''create 
+            view `dim_v3` COMMENT 'VIEW' as
+            select
+                case
+                        when `t`.`date_tag` = '月_T+1' then '本月'
+                        else `t`.`date_tag`
+                    end
+                as `date_tag`
+            from
+                `dim_v2` t 
+            left outer join (
+                    select
+                        distinct `date_tag` as `date_tag`
+                    from
+                        `dim_v2`
+                ) t1 on
+                `t`.`date_tag` = `t1`.`date_tag`
+            group by
+                1;'''
+
+    qt_select1 '''select distinct date_tag from dim_v3 where date_tag='本日';'''
+
+    sql 'drop view if exists dim_v2'
+    sql 'drop view if exists dim_v3'
+    sql 'drop table if exists test_distinct_agg_t'
 }
\ 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