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

yangzhg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new ee26cd2  [fix] (grouping set) fix Unexpected exception: bitIndex < 0: 
-1 (#7989)
ee26cd2 is described below

commit ee26cd2d078c782ac2d7a086d81bbe3c2e3ab1f1
Author: Zhengguo Yang <yangz...@gmail.com>
AuthorDate: Sat Feb 12 15:18:08 2022 +0800

    [fix] (grouping set) fix Unexpected exception: bitIndex < 0: -1 (#7989)
---
 .../org/apache/doris/analysis/GroupingInfo.java    | 10 ++++++---
 .../java/org/apache/doris/analysis/SelectStmt.java |  3 +--
 .../apache/doris/analysis/GroupByClauseTest.java   | 18 +++++++--------
 .../org/apache/doris/planner/QueryPlanTest.java    | 26 ++++++++++++++++++++++
 4 files changed, 43 insertions(+), 14 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupingInfo.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupingInfo.java
index e1e7961..41f544d 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupingInfo.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupingInfo.java
@@ -33,7 +33,7 @@ import java.util.stream.Collectors;
 
 public class GroupingInfo {
     public static final String COL_GROUPING_ID = "GROUPING_ID";
-
+    private GroupByClause groupByClause;
     private VirtualSlotRef groupingIDSlot;
     private TupleDescriptor virtualTuple;
     private Set<VirtualSlotRef> groupingSlots;
@@ -41,8 +41,9 @@ public class GroupingInfo {
     private GroupByClause.GroupingType groupingType;
     private BitSet bitSetAll;
 
-    public GroupingInfo(Analyzer analyzer, GroupByClause.GroupingType 
groupingType) throws AnalysisException {
-        this.groupingType = groupingType;
+    public GroupingInfo(Analyzer analyzer, GroupByClause groupByClause) throws 
AnalysisException {
+        this.groupByClause = groupByClause;
+        this.groupingType = groupByClause.getGroupingType();
         groupingSlots = new LinkedHashSet<>();
         virtualTuple = 
analyzer.getDescTbl().createTupleDescriptor("VIRTUAL_TUPLE");
         groupingIDSlot = new VirtualSlotRef(COL_GROUPING_ID, Type.BIGINT, 
virtualTuple, new ArrayList<>());
@@ -190,6 +191,9 @@ public class GroupingInfo {
                     if (colIndex != -1 && 
!(ref.getViewStmt().getResultExprs().get(colIndex) instanceof SlotRef)) {
                         throw new AnalysisException("grouping functions only 
support column in current version.");
                     }
+                } else if (!groupByClause.getGroupingExprs().contains(child)) {
+                    throw new AnalysisException("select list expression not 
produced by aggregation output" +
+                            " (missing from GROUP BY clause?): " + ((SlotRef) 
child).getColumnName());
                 }
             }
             // if is substituted skip
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
index 2b1edb2..502a7fd 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
@@ -447,7 +447,7 @@ public class SelectStmt extends QueryStmt {
                     }
                 }
             }
-            groupingInfo = new GroupingInfo(analyzer, 
groupByClause.getGroupingType());
+            groupingInfo = new GroupingInfo(analyzer, groupByClause);
             groupingInfo.substituteGroupingFn(resultExprs, analyzer);
         } else {
             for (Expr expr : resultExprs) {
@@ -1881,4 +1881,3 @@ public class SelectStmt extends QueryStmt {
         return this.id.equals(((SelectStmt) obj).id);
     }
 }
-
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/analysis/GroupByClauseTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/analysis/GroupByClauseTest.java
index e105863..67f2dc5 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/analysis/GroupByClauseTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/GroupByClauseTest.java
@@ -83,10 +83,10 @@ public class GroupByClauseTest {
                 GroupByClause.GroupingType.GROUPING_SETS);
         GroupingInfo groupingInfo = null;
         try {
-            groupingInfo = new GroupingInfo(analyzer, 
GroupByClause.GroupingType.GROUPING_SETS);
             groupByClause.genGroupingExprs();
-            groupingInfo.buildRepeat(groupByClause.getGroupingExprs(), 
groupByClause.getGroupingSetList());
             groupByClause.analyze(analyzer);
+            groupingInfo = new GroupingInfo(analyzer, groupByClause);
+            groupingInfo.buildRepeat(groupByClause.getGroupingExprs(), 
groupByClause.getGroupingSetList());
         } catch (AnalysisException exception) {
             exception.printStackTrace();
             Assert.assertTrue(false);
@@ -124,10 +124,10 @@ public class GroupByClauseTest {
                         GroupByClause.GroupingType.ROLLUP);
         GroupingInfo groupingInfo = null;
         try {
-            groupingInfo = new GroupingInfo(analyzer, 
GroupByClause.GroupingType.ROLLUP);
             groupByClause.genGroupingExprs();
-            groupingInfo.buildRepeat(groupByClause.getGroupingExprs(), 
groupByClause.getGroupingSetList());
             groupByClause.analyze(analyzer);
+            groupingInfo = new GroupingInfo(analyzer, groupByClause);
+            groupingInfo.buildRepeat(groupByClause.getGroupingExprs(), 
groupByClause.getGroupingSetList());
         } catch (AnalysisException execption) {
             Assert.assertTrue(false);
         }
@@ -160,10 +160,10 @@ public class GroupByClauseTest {
                 GroupByClause.GroupingType.CUBE);
         GroupingInfo groupingInfo = null;
         try {
-            groupingInfo = new GroupingInfo(analyzer, 
GroupByClause.GroupingType.CUBE);
             groupByClause.genGroupingExprs();
-            groupingInfo.buildRepeat(groupByClause.getGroupingExprs(), 
groupByClause.getGroupingSetList());
             groupByClause.analyze(analyzer);
+            groupingInfo = new GroupingInfo(analyzer, groupByClause);
+            groupingInfo.buildRepeat(groupByClause.getGroupingExprs(), 
groupByClause.getGroupingSetList());
         } catch (AnalysisException exception) {
             Assert.assertTrue(false);
         }
@@ -264,11 +264,11 @@ public class GroupByClauseTest {
         }
         GroupingInfo groupingInfo = null;
         try {
-            groupingInfo = new GroupingInfo(analyzer, 
GroupByClause.GroupingType.CUBE);
-            groupingInfo.addGroupingSlots(slots, analyzer);
             groupByClause.genGroupingExprs();
-            groupingInfo.buildRepeat(groupByClause.getGroupingExprs(), 
groupByClause.getGroupingSetList());
             groupByClause.analyze(analyzer);
+            groupingInfo = new GroupingInfo(analyzer, groupByClause);
+            groupingInfo.addGroupingSlots(slots, analyzer);
+            groupingInfo.buildRepeat(groupByClause.getGroupingExprs(), 
groupByClause.getGroupingSetList());
         } catch (AnalysisException exception) {
             Assert.assertTrue(false);
         }
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
index 9ef045c..5e876a1 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
@@ -1962,4 +1962,30 @@ public class QueryPlanTest {
     }
     // --end--
 
+    @Test
+    public void testGroupingSets() throws Exception {
+        String createDbStmtStr = "create database issue7971;";
+        CreateDbStmt createDbStmt = (CreateDbStmt) 
UtFrameUtils.parseAndAnalyzeStmt(createDbStmtStr, connectContext);
+        Catalog.getCurrentCatalog().createDb(createDbStmt);
+        createTable("CREATE TABLE issue7971.`t` (\n" +
+                "  `k1` tinyint(4) NULL COMMENT \"\",\n" +
+                "  `k2` smallint(6) NULL COMMENT \"\",\n" +
+                "  `k3` smallint(6) NULL COMMENT \"\"\n" +
+                ") ENGINE=OLAP\n" +
+                "DUPLICATE KEY(`k1`, `k2`)\n" +
+                "COMMENT \"OLAP\"\n" +
+                "DISTRIBUTED BY HASH(`k1`) BUCKETS 1\n" +
+                "PROPERTIES (\n" +
+                "\"replication_allocation\" = \"tag.location.default: 1\",\n" +
+                "\"in_memory\" = \"false\",\n" +
+                "\"storage_format\" = \"V2\"\n" +
+                ")");
+        String sql = "SELECT k1, k2, GROUPING(k1), GROUPING(k2), SUM(k3) FROM 
issue7971.t GROUP BY GROUPING SETS ( (k1, k2), (k2), (k1), ( ) );";
+        String explainStr = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, 
sql);
+        Assert.assertTrue(explainStr.contains("REPEAT_NODE"));
+        sql = "SELECT k1 ,GROUPING(k2) FROM issue7971.t GROUP BY CUBE (k1) 
ORDER BY k1;";
+        explainStr = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, sql);
+        Assert.assertTrue(explainStr.contains("errCode = 2"));
+    }
+
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to