imay commented on a change in pull request #2293: Support Grouping Sets, Rollup 
and Cube to extend group by statement
URL: https://github.com/apache/incubator-doris/pull/2293#discussion_r352284531
 
 

 ##########
 File path: fe/src/main/java/org/apache/doris/analysis/GroupByClause.java
 ##########
 @@ -0,0 +1,447 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.analysis;
+
+import org.apache.doris.catalog.Type;
+import org.apache.doris.common.AnalysisException;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicates;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Wraps all information of group by clause.
+ */
+public class GroupByClause implements ParseNode {
+    private final static Logger LOG = 
LogManager.getLogger(GroupByClause.class);
+
+    // max num of distinct sets in grouping sets clause
+    private final static int MAX_GROUPING_SETS_NUM = 16;
+    // max num of distinct expressions
+    private final static int MAX_GROUPING_SETS_EXPRESSION_NUM = 64;
+    private final static String VIRTUAL_TUPLE = "VIRTUAL_TUPLE";
+    private boolean analyzed_ = false;
+    private boolean exprGenerated = false;
+    private GroupingType groupingType;
+    private ArrayList<Expr> groupingExprs;
+    private ArrayList<Expr> oriGroupingExprs;
+    private List<BitSet> groupingIdList;
+    // grouping functions virtual slot
+    private Set<VirtualSlotRef> groupingSlots;
+    // reserve this info for toSQL
+    private List<ArrayList<Expr>> groupingSetList;
+    private TupleDescriptor virtualTuple;
+
+    public GroupByClause(List<ArrayList<Expr>> groupingSetList, GroupingType 
type) {
+        this.groupingType = type;
+        this.groupingSetList = groupingSetList;
+        this.groupingIdList = new ArrayList<>();
+        Preconditions.checkState(type == GroupingType.GROUPING_SETS);
+        groupingSlots = new HashSet<>();
+        virtualTuple = null;
+    }
+
+    public GroupByClause(ArrayList<Expr> groupingExprs, GroupingType type) {
+        this.groupingType = type;
+        this.oriGroupingExprs = groupingExprs;
+        this.groupingExprs = new ArrayList<>();
+        this.groupingExprs.addAll(oriGroupingExprs);
+        this.groupingIdList = new ArrayList<>();
+        Preconditions.checkState(type != GroupingType.GROUPING_SETS);
+        groupingSlots = new HashSet<>();
+        virtualTuple = null;
+    }
+    protected GroupByClause(GroupByClause other) {
+        this.groupingType = other.groupingType;
+        this.groupingExprs = (other.groupingExprs != null) ? 
Expr.cloneAndResetList(other.groupingExprs) : null;
+        this.oriGroupingExprs =
+                (other.oriGroupingExprs != null) ? 
Expr.cloneAndResetList(other.oriGroupingExprs) : null;
+        if (other.groupingIdList != null) {
+            this.groupingIdList = new ArrayList<>();
+            for (BitSet bitSet : other.groupingIdList) {
+                this.groupingIdList.add((BitSet) bitSet.clone());
+            }
+        } else {
+            this.groupingIdList = new ArrayList<>();
+        }
+
+        if (other.groupingSetList != null) {
+            this.groupingSetList = new ArrayList<>();
+            for (List<Expr> exprList : other.groupingSetList) {
+                this.groupingSetList.add(Expr.cloneAndResetList(exprList));
+            }
+        }
+        if (other.groupingSlots != null) {
+            this.groupingSlots = new HashSet<>(Expr.cloneList(new 
ArrayList(other.groupingSlots)));
+        }
+        this.virtualTuple = other.virtualTuple;
+    }
+
+    public void reset() {
+        groupingExprs = new ArrayList<>();
+        analyzed_ = false;
+        exprGenerated = false;
+        if (oriGroupingExprs != null) {
+            Expr.resetList(oriGroupingExprs);
+            groupingExprs.addAll(oriGroupingExprs);
+        }
+        groupingIdList = new ArrayList<>();
+        groupingSlots = new HashSet<>();
+        if (groupingSetList != null) {
+            for (List<Expr> s : groupingSetList) {
+                for (Expr e : s) {
+                    if (e != null) {
+                        e.reset();
+                    }
+                }
+            }
+        }
+        virtualTuple = null;
+    }
+
+    public ArrayList<Expr> getGroupingExprs() {
+        Preconditions.checkState(exprGenerated);
+        return groupingExprs;
+    }
+
+    public TupleDescriptor getGroupingTuple() {
 
 Review comment:
   This class is generated in SQL parse stage, but TupleDescriptor is something 
should be generated in execution stage. So I think it isn't appropriate to 
return a tuple here.
   
   Maybe you can generate another class to achieve this.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to