seawinde opened a new pull request, #57741:
URL: https://github.com/apache/doris/pull/57741

   ### What problem does this PR solve?
   Fix query rewrite by mv fail when both use cte and group sets
   
   Such as mv def is as following:
   ```sql
               select l_shipdate, o_orderdate, l_partkey, l_suppkey,
               sum(o_totalprice) as sum_total,
               max(o_totalprice) as max_total,
               min(o_totalprice) as min_total,
               count(*) as count_all,
               bitmap_union(to_bitmap(case when o_shippriority > 1 and 
o_orderkey IN (1, 3) then o_custkey else null end)) as bitmap_union_basic
               from lineitem
               left join orders on lineitem.l_orderkey = orders.o_orderkey and 
l_shipdate = o_orderdate
               group by
               l_shipdate,
               o_orderdate,
               l_partkey,
               l_suppkey;
   ```
   
   query is as fllowing, use both group sets and cte, would rewrite fail, the 
pr fix this
   
   ```sql
               with t as (
                   select t1.l_partkey, t1.l_suppkey, o_orderdate,
                   grouping(t1.l_suppkey),
                   grouping(o_orderdate),
                   grouping_id(t1.l_partkey, t1.l_suppkey),
                   grouping_id(t1.l_partkey, t1.l_suppkey, o_orderdate),
                   sum(o_totalprice),
                   max(o_totalprice),
                   min(o_totalprice),
                   count(*),
                   count(distinct case when o_shippriority > 1 and o_orderkey 
IN (1, 3) then o_custkey else null end)
                   from (select * from lineitem where l_shipdate = 
'2023-12-11') t1
                   left join orders on t1.l_orderkey = orders.o_orderkey and 
t1.l_shipdate = o_orderdate
                   group by
                   GROUPING SETS ((l_shipdate, o_orderdate, l_partkey), 
(l_partkey, l_suppkey), (l_suppkey), ())
               )
               select t1.l_suppkey, t2.o_orderdate
               from
               t t1
               inner join
               t t2 on t1.l_partkey = t2.l_partkey;
   ```
   
   
   Issue Number: close #xxx
   
   Related PR: #36056 
   
   Problem Summary:
   
   ### Release note
   
   None
   
   ### Check List (For Author)
   
   - Test <!-- At least one of them must be included. -->
       - [ ] Regression test
       - [ ] Unit Test
       - [ ] Manual test (add detailed scripts or steps below)
       - [ ] No need to test or manual test. Explain why:
           - [ ] This is a refactor/code format and no logic has been changed.
           - [ ] Previous test can cover this change.
           - [ ] No code files have been changed.
           - [ ] Other reason <!-- Add your reason?  -->
   
   - Behavior changed:
       - [ ] No.
       - [ ] Yes. <!-- Explain the behavior change -->
   
   - Does this need documentation?
       - [ ] No.
       - [ ] Yes. <!-- Add document PR link here. eg: 
https://github.com/apache/doris-website/pull/1214 -->
   
   ### Check List (For Reviewer who merge this PR)
   
   - [ ] Confirm the release note
   - [ ] Confirm test cases
   - [ ] Confirm document
   - [ ] Add branch pick label <!-- Add branch pick label that this PR should 
merge into -->
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to