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

 ##########
 File path: fe/src/main/java/org/apache/doris/analysis/GroupByClause.java
 ##########
 @@ -0,0 +1,321 @@
+// 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 com.google.common.base.Preconditions;
+import com.google.common.base.Predicates;
+import org.apache.doris.catalog.Type;
+import org.apache.doris.common.AnalysisException;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.*;
+
+/**
+ * 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;
+    // GROUPING_ID is a fake column
+    private final static String GROUPING__ID = "GROUPING__ID";
+
+    public enum GroupingType {
+        GROUP_BY,
+        GROUPING_SETS,
+        ROLLUP,
+        CUBE;
+    };
+
+    private boolean analyzed_ = false;
+    private GroupingType groupingType;
+    private ArrayList<Expr> groupingExprs;
+    private List<BitSet> groupingIdList;
+    private SlotRef groupingIdSlotRef;
+
+    // reserve this info for toSQL
+    private List<ArrayList<Expr>> groupingSetList;
+
+    public GroupByClause(List<ArrayList<Expr>> groupingSetList, GroupingType 
type) {
+        this.groupingType = type;
+        this.groupingSetList = groupingSetList;
+        Preconditions.checkState(type == GroupingType.GROUPING_SETS);
+    }
+
+    public GroupByClause(ArrayList<Expr> groupingExprs, GroupingType type) {
+        this.groupingType = type;
+        this.groupingExprs = groupingExprs;
+        Preconditions.checkState(type != GroupingType.GROUPING_SETS);
+    }
+
+    public ArrayList<Expr> getGroupingExprs() {
+        Preconditions.checkState(analyzed_);
+        return groupingExprs;
+    }
+
+    public void setGroupingExprs(ArrayList<Expr> groupingExprs) {
+        this.groupingExprs = groupingExprs;
+    }
+
+    protected GroupByClause(GroupByClause other) {
+        this.groupingType = other.groupingType;
+        this.groupingExprs = Expr.cloneAndResetList(groupingExprs);
+        this.groupingIdList = other.groupingIdList;
+        this.groupingSetList = other.groupingSetList;
+    }
 
 Review comment:
   why do groupingIdList and groupingIdList use references ? clone these.

----------------------------------------------------------------
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