You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by jc...@apache.org on 2020/10/07 22:03:24 UTC

[hive] branch master updated: HIVE-24232: Incorrect translation of rollup expression from Calcite (Jesus Camacho Rodriguez, reviewed by Ashutosh Chauhan, Vineet Garg, Krisztian Kasa)

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

jcamacho pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/master by this push:
     new 1507d80  HIVE-24232: Incorrect translation of rollup expression from Calcite (Jesus Camacho Rodriguez, reviewed by Ashutosh Chauhan, Vineet Garg, Krisztian Kasa)
1507d80 is described below

commit 1507d80fd47aad38b87bba4fd58c1427ba89dbbf
Author: Jesús Camacho Rodríguez <jc...@apache.org>
AuthorDate: Wed Oct 7 15:03:05 2020 -0700

    HIVE-24232: Incorrect translation of rollup expression from Calcite (Jesus Camacho Rodriguez, reviewed by Ashutosh Chauhan, Vineet Garg, Krisztian Kasa)
    
    Closes apache/hive#1554
---
 .../test/resources/testconfiguration.properties    |   2 +
 .../optimizer/calcite/translator/ASTConverter.java |   8 +-
 .../apache/hadoop/hive/ql/plan/GroupByDesc.java    |   7 +-
 .../clientpositive/perf/cbo_query_grouping_sets.q  |  49 +++
 .../llap/annotate_stats_groupby.q.out              |  16 +
 .../llap/annotate_stats_groupby2.q.out             |   3 +
 .../llap/auto_join18_multi_distinct.q.out          |   1 +
 .../llap/cbo_rp_annotate_stats_groupby.q.out       |  16 +
 .../clientpositive/llap/groupby_cube1.q.out        |   8 +
 .../llap/groupby_cube_multi_gby.q.out              |   2 +
 .../clientpositive/llap/groupby_grouping_id3.q.out |   2 +
 .../llap/groupby_grouping_sets1.q.out              |   5 +
 .../llap/groupby_grouping_sets2.q.out              |   4 +
 .../llap/groupby_grouping_sets3.q.out              |   3 +
 .../llap/groupby_grouping_sets4.q.out              |   3 +
 .../llap/groupby_grouping_sets5.q.out              |   3 +
 .../llap/groupby_grouping_sets6.q.out              |   2 +
 .../llap/groupby_grouping_sets_grouping.q.out      |  12 +
 .../llap/groupby_grouping_sets_limit.q.out         |   4 +
 .../llap/groupby_grouping_sets_pushdown1.q.out     |   9 +
 .../llap/groupby_grouping_window.q.out             |   1 +
 .../clientpositive/llap/groupby_rollup1.q.out      |   6 +
 .../clientpositive/llap/groupby_rollup_empty.q.out |   1 +
 .../llap/groupby_rollup_empty2.q.out               |   1 +
 .../infer_bucket_sort_grouping_operators.q.out     |   3 +
 .../llap/join18_multi_distinct.q.out               |   1 +
 .../clientpositive/llap/limit_pushdown.q.out       |   1 +
 .../clientpositive/llap/limit_pushdown2.q.out      |   2 +
 .../clientpositive/llap/limit_pushdown3.q.out      |   1 +
 .../llap/multi_count_distinct_null.q.out           |   2 +
 .../llap/offset_limit_ppd_optimizer.q.out          |   1 +
 .../llap/reduce_deduplicate_distinct.q.out         |   5 +
 .../llap/topnkey_grouping_sets.q.out               |  10 +
 .../llap/topnkey_grouping_sets_functions.q.out     |   3 +
 .../llap/topnkey_grouping_sets_order.q.out         |   4 +
 .../clientpositive/llap/vector_groupby_cube1.q.out |   8 +
 .../llap/vector_groupby_grouping_id1.q.out         |   6 +
 .../llap/vector_groupby_grouping_id2.q.out         |   9 +
 .../llap/vector_groupby_grouping_id3.q.out         |   2 +
 .../llap/vector_groupby_grouping_sets1.q.out       |   5 +
 .../llap/vector_groupby_grouping_sets2.q.out       |   4 +
 .../llap/vector_groupby_grouping_sets3.q.out       |   3 +
 .../llap/vector_groupby_grouping_sets3_dec.q.out   |   3 +
 .../llap/vector_groupby_grouping_sets4.q.out       |   3 +
 .../llap/vector_groupby_grouping_sets5.q.out       |   3 +
 .../llap/vector_groupby_grouping_sets6.q.out       |   2 +
 .../vector_groupby_grouping_sets_grouping.q.out    |  12 +
 .../llap/vector_groupby_grouping_sets_limit.q.out  |   4 +
 .../llap/vector_groupby_grouping_window.q.out      |   1 +
 .../llap/vector_groupby_rollup1.q.out              |   6 +
 .../clientpositive/llap/vector_grouping_sets.q.out |   3 +
 .../results/clientpositive/llap/view_cbo.q.out     |   1 +
 .../tez/constraints/cbo_query_grouping_sets.q.out  | 464 +++++++++++++++++++++
 53 files changed, 732 insertions(+), 8 deletions(-)

diff --git a/itests/src/test/resources/testconfiguration.properties b/itests/src/test/resources/testconfiguration.properties
index 3680dc7..a7d5c91 100644
--- a/itests/src/test/resources/testconfiguration.properties
+++ b/itests/src/test/resources/testconfiguration.properties
@@ -1083,6 +1083,7 @@ spark.only.query.negative.files=\
   spark_task_failure.q
 
 tez.perf.disabled.query.files=\
+  cbo_query_grouping_sets.q,\
   mv_query30.q,\
   mv_query44.q,\
   mv_query45.q,\
@@ -1188,6 +1189,7 @@ spark.perf.disabled.query.files=\
   cbo_query97.q,\
   cbo_query98.q,\
   cbo_query99.q,\
+  cbo_query_grouping_sets.q,\
   mv_query30.q,\
   mv_query44.q,\
   mv_query45.q,\
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/ASTConverter.java b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/ASTConverter.java
index 072a27d..4fe7f7d 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/ASTConverter.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/ASTConverter.java
@@ -154,11 +154,7 @@ public class ASTConverter {
           b = ASTBuilder.construct(HiveParser.TOK_GROUPBY, "TOK_GROUPBY");
           break;
         case ROLLUP:
-          b = ASTBuilder.construct(HiveParser.TOK_ROLLUP_GROUPBY, "TOK_ROLLUP_GROUPBY");
-          break;
         case CUBE:
-          b = ASTBuilder.construct(HiveParser.TOK_CUBE_GROUPBY, "TOK_CUBE_GROUPBY");
-          break;
         case OTHER:
           b = ASTBuilder.construct(HiveParser.TOK_GROUPING_SETS, "TOK_GROUPING_SETS");
           groupingSetsExpression = true;
@@ -191,9 +187,7 @@ public class ASTConverter {
           ASTBuilder expression = ASTBuilder.construct(
                   HiveParser.TOK_GROUPING_SETS_EXPRESSION, "TOK_GROUPING_SETS_EXPRESSION");
           for (int i : groupSet) {
-            RexInputRef iRef = new RexInputRef(i, groupBy.getCluster().getTypeFactory()
-                .createSqlType(SqlTypeName.ANY));
-            expression.add(iRef.accept(new RexVisitor(schema, false, root.getCluster().getRexBuilder())));
+            addRefToBuilder(expression, i);
           }
           b.add(expression);
         }
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/plan/GroupByDesc.java b/ql/src/java/org/apache/hadoop/hive/ql/plan/GroupByDesc.java
index 09b0d7a..f34a94d 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/plan/GroupByDesc.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/plan/GroupByDesc.java
@@ -284,8 +284,13 @@ public class GroupByDesc extends AbstractOperatorDesc {
   // in which case the group by would execute as a single map-reduce job.
   // For the group-by, the group by keys should be: a,b,groupingSet(for rollup), c
   // So, the starting position of grouping set need to be known
+  @Explain(displayName = "grouping sets")
+  @Signature
   public List<Long> getListGroupingSets() {
-    return listGroupingSets;
+    if (groupingSetsPresent) {
+      return listGroupingSets;
+    }
+    return null;
   }
 
   public void setListGroupingSets(final List<Long> listGroupingSets) {
diff --git a/ql/src/test/queries/clientpositive/perf/cbo_query_grouping_sets.q b/ql/src/test/queries/clientpositive/perf/cbo_query_grouping_sets.q
new file mode 100644
index 0000000..3c7845a
--- /dev/null
+++ b/ql/src/test/queries/clientpositive/perf/cbo_query_grouping_sets.q
@@ -0,0 +1,49 @@
+EXPLAIN CBO
+select  
+        ca_country, ca_state, i_item_id,
+         avg( cast(cs_quantity as numeric(12,2))) agg1,
+         avg( cast(c_birth_year as numeric(12,2))) agg6,
+         avg( cast(cd1.cd_dep_count as numeric(12,2))) agg7
+from catalog_sales, customer_demographics cd1,
+        customer, customer_address,
+        date_dim,
+        item
+where cs_sold_date_sk = d_date_sk and
+        cs_item_sk = i_item_sk and
+        cs_bill_cdemo_sk = cd1.cd_demo_sk and
+        cs_bill_customer_sk = c_customer_sk and
+        cd1.cd_gender = 'M' and
+        cd1.cd_education_status = 'College' and
+        c_current_addr_sk = ca_address_sk and
+        c_birth_month in (9,5) and
+        d_year = 2001 and
+        ca_state in ('AL','MS','TN')
+group by rollup(i_item_id, ca_country, ca_state)
+order by ca_country, ca_state, i_item_id NULLS FIRST
+limit 100;
+
+set hive.explain.user=false;
+
+EXPLAIN
+select  
+        ca_country, ca_state, i_item_id,
+         avg( cast(cs_quantity as numeric(12,2))) agg1,
+         avg( cast(c_birth_year as numeric(12,2))) agg6,
+         avg( cast(cd1.cd_dep_count as numeric(12,2))) agg7
+from catalog_sales, customer_demographics cd1,
+        customer, customer_address,
+        date_dim,
+        item
+where cs_sold_date_sk = d_date_sk and
+        cs_item_sk = i_item_sk and
+        cs_bill_cdemo_sk = cd1.cd_demo_sk and
+        cs_bill_customer_sk = c_customer_sk and
+        cd1.cd_gender = 'M' and
+        cd1.cd_education_status = 'College' and
+        c_current_addr_sk = ca_address_sk and
+        c_birth_month in (9,5) and
+        d_year = 2001 and
+        ca_state in ('AL','MS','TN')
+group by rollup(i_item_id, ca_country, ca_state)
+order by ca_country, ca_state, i_item_id NULLS FIRST
+limit 100;
diff --git a/ql/src/test/results/clientpositive/llap/annotate_stats_groupby.q.out b/ql/src/test/results/clientpositive/llap/annotate_stats_groupby.q.out
index 00c1073..a4e2654 100644
--- a/ql/src/test/results/clientpositive/llap/annotate_stats_groupby.q.out
+++ b/ql/src/test/results/clientpositive/llap/annotate_stats_groupby.q.out
@@ -358,6 +358,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 720 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: state (type: string), locid (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -424,6 +425,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 720 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: state (type: string), locid (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -490,6 +492,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 720 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: state (type: string), locid (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -556,6 +559,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 720 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: state (type: string), locid (type: int), 0L (type: bigint)
+                      grouping sets: 1
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -622,6 +626,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 720 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: state (type: string), locid (type: int), 0L (type: bigint)
+                      grouping sets: 1, 2
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -688,6 +693,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 720 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: state (type: string), locid (type: int), 0L (type: bigint)
+                      grouping sets: 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -754,6 +760,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 720 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: state (type: string), locid (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -885,6 +892,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 720 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: state (type: string), locid (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1016,6 +1024,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 796 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: state (type: string), locid (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1082,6 +1091,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 796 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: state (type: string), locid (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1148,6 +1158,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 796 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: state (type: string), locid (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1214,6 +1225,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 796 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: state (type: string), locid (type: int), 0L (type: bigint)
+                      grouping sets: 1
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1280,6 +1292,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 796 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: state (type: string), locid (type: int), 0L (type: bigint)
+                      grouping sets: 1, 2
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1346,6 +1359,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 796 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: state (type: string), locid (type: int), 0L (type: bigint)
+                      grouping sets: 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1412,6 +1426,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 796 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: state (type: string), locid (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1543,6 +1558,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 796 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: state (type: string), locid (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
diff --git a/ql/src/test/results/clientpositive/llap/annotate_stats_groupby2.q.out b/ql/src/test/results/clientpositive/llap/annotate_stats_groupby2.q.out
index 66f8728..264a217 100644
--- a/ql/src/test/results/clientpositive/llap/annotate_stats_groupby2.q.out
+++ b/ql/src/test/results/clientpositive/llap/annotate_stats_groupby2.q.out
@@ -132,6 +132,7 @@ STAGE PLANS:
                     Statistics: Num rows: 20 Data size: 200 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: state (type: string), country (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -328,6 +329,7 @@ STAGE PLANS:
                     Statistics: Num rows: 20 Data size: 3460 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: state (type: string), country (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.9
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -459,6 +461,7 @@ STAGE PLANS:
                     Statistics: Num rows: 20 Data size: 3460 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: state (type: string), country (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.9
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
diff --git a/ql/src/test/results/clientpositive/llap/auto_join18_multi_distinct.q.out b/ql/src/test/results/clientpositive/llap/auto_join18_multi_distinct.q.out
index 0e3b039..f6095bc 100644
--- a/ql/src/test/results/clientpositive/llap/auto_join18_multi_distinct.q.out
+++ b/ql/src/test/results/clientpositive/llap/auto_join18_multi_distinct.q.out
@@ -83,6 +83,7 @@ STAGE PLANS:
                     Statistics: Num rows: 25 Data size: 4375 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: _col0 (type: string), _col1 (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
diff --git a/ql/src/test/results/clientpositive/llap/cbo_rp_annotate_stats_groupby.q.out b/ql/src/test/results/clientpositive/llap/cbo_rp_annotate_stats_groupby.q.out
index d34933f..0f6bac7 100644
--- a/ql/src/test/results/clientpositive/llap/cbo_rp_annotate_stats_groupby.q.out
+++ b/ql/src/test/results/clientpositive/llap/cbo_rp_annotate_stats_groupby.q.out
@@ -358,6 +358,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 720 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: state (type: string), locid (type: int), '0L' (type: string)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -423,6 +424,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 720 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: state (type: string), locid (type: int), '0L' (type: string)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -488,6 +490,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 720 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: state (type: string), locid (type: int), '0L' (type: string)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -553,6 +556,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 720 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: state (type: string), locid (type: int), '0L' (type: string)
+                      grouping sets: 1
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -618,6 +622,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 720 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: state (type: string), locid (type: int), '0L' (type: string)
+                      grouping sets: 1, 2
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -683,6 +688,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 720 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: state (type: string), locid (type: int), '0L' (type: string)
+                      grouping sets: 0, 1, 2
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -748,6 +754,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 720 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: state (type: string), locid (type: int), '0L' (type: string)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -878,6 +885,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 720 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: state (type: string), locid (type: int), '0L' (type: string)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1008,6 +1016,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 796 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: state (type: string), locid (type: int), '0L' (type: string)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1073,6 +1082,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 796 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: state (type: string), locid (type: int), '0L' (type: string)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1138,6 +1148,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 796 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: state (type: string), locid (type: int), '0L' (type: string)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1203,6 +1214,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 796 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: state (type: string), locid (type: int), '0L' (type: string)
+                      grouping sets: 1
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1268,6 +1280,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 796 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: state (type: string), locid (type: int), '0L' (type: string)
+                      grouping sets: 1, 2
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1333,6 +1346,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 796 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: state (type: string), locid (type: int), '0L' (type: string)
+                      grouping sets: 0, 1, 2
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1398,6 +1412,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 796 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: state (type: string), locid (type: int), '0L' (type: string)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1528,6 +1543,7 @@ STAGE PLANS:
                     Statistics: Num rows: 8 Data size: 796 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: state (type: string), locid (type: int), '0L' (type: string)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
diff --git a/ql/src/test/results/clientpositive/llap/groupby_cube1.q.out b/ql/src/test/results/clientpositive/llap/groupby_cube1.q.out
index 09baad9..07c24f4 100644
--- a/ql/src/test/results/clientpositive/llap/groupby_cube1.q.out
+++ b/ql/src/test/results/clientpositive/llap/groupby_cube1.q.out
@@ -48,6 +48,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count()
                       keys: key (type: string), val (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -123,6 +124,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count()
                       keys: key (type: string), val (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -224,6 +226,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count()
                       keys: _col0 (type: string), _col1 (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -324,6 +327,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count(DISTINCT val)
                       keys: key (type: string), 0L (type: bigint), val (type: string)
+                      grouping sets: 0, 1
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -413,6 +417,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count()
                       keys: key (type: string), val (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -531,6 +536,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count(DISTINCT val)
                       keys: key (type: string), 0L (type: bigint), val (type: string)
+                      grouping sets: 0, 1
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -666,6 +672,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count(1)
                       keys: key (type: string), val (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -684,6 +691,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: sum(1)
                       keys: key (type: string), val (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/groupby_cube_multi_gby.q.out b/ql/src/test/results/clientpositive/llap/groupby_cube_multi_gby.q.out
index 284b323..f776be3 100644
--- a/ql/src/test/results/clientpositive/llap/groupby_cube_multi_gby.q.out
+++ b/ql/src/test/results/clientpositive/llap/groupby_cube_multi_gby.q.out
@@ -66,6 +66,7 @@ STAGE PLANS:
                     Statistics: Num rows: 500 Data size: 89000 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: key (type: string), value (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -82,6 +83,7 @@ STAGE PLANS:
                     Statistics: Num rows: 500 Data size: 89000 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: key (type: string), value (type: string), 0L (type: bigint)
+                      grouping sets: 1, 0
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
diff --git a/ql/src/test/results/clientpositive/llap/groupby_grouping_id3.q.out b/ql/src/test/results/clientpositive/llap/groupby_grouping_id3.q.out
index 4265bcb..7703464 100644
--- a/ql/src/test/results/clientpositive/llap/groupby_grouping_id3.q.out
+++ b/ql/src/test/results/clientpositive/llap/groupby_grouping_id3.q.out
@@ -56,6 +56,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count()
                       keys: key (type: int), value (type: int), 0L (type: bigint)
+                      grouping sets: 3, 1
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -162,6 +163,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count()
                       keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                      grouping sets: 1, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/groupby_grouping_sets1.q.out b/ql/src/test/results/clientpositive/llap/groupby_grouping_sets1.q.out
index 87319e1..f2a7f90 100644
--- a/ql/src/test/results/clientpositive/llap/groupby_grouping_sets1.q.out
+++ b/ql/src/test/results/clientpositive/llap/groupby_grouping_sets1.q.out
@@ -64,6 +64,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count()
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -164,6 +165,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count()
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -264,6 +266,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count()
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -364,6 +367,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count()
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -459,6 +463,7 @@ STAGE PLANS:
                     Statistics: Num rows: 1 Data size: 552 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: a (type: string), b (type: string), c (type: string), 0L (type: bigint)
+                      grouping sets: 3, 5, 6
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/groupby_grouping_sets2.q.out b/ql/src/test/results/clientpositive/llap/groupby_grouping_sets2.q.out
index e6d800f..ac56632 100644
--- a/ql/src/test/results/clientpositive/llap/groupby_grouping_sets2.q.out
+++ b/ql/src/test/results/clientpositive/llap/groupby_grouping_sets2.q.out
@@ -69,6 +69,7 @@ STAGE PLANS:
               Group By Operator
                 aggregations: count(VALUE._col0)
                 keys: KEY._col0 (type: string), KEY._col1 (type: string), 0L (type: bigint)
+                grouping sets: 0, 1, 2, 3
                 mode: partials
                 outputColumnNames: _col0, _col1, _col2, _col3
                 Statistics: Num rows: 4 Data size: 1472 Basic stats: COMPLETE Column stats: NONE
@@ -162,6 +163,7 @@ STAGE PLANS:
               Group By Operator
                 aggregations: count(VALUE._col0)
                 keys: KEY._col0 (type: string), KEY._col1 (type: string), 0L (type: bigint)
+                grouping sets: 0, 1, 2, 3
                 mode: partials
                 outputColumnNames: _col0, _col1, _col2, _col3
                 Statistics: Num rows: 4 Data size: 1472 Basic stats: COMPLETE Column stats: NONE
@@ -279,6 +281,7 @@ STAGE PLANS:
               Group By Operator
                 aggregations: sum(VALUE._col0)
                 keys: KEY._col0 (type: string), KEY._col1 (type: string), 0L (type: bigint)
+                grouping sets: 0, 1, 2, 3
                 mode: partials
                 outputColumnNames: _col0, _col1, _col2, _col3
                 Statistics: Num rows: 4 Data size: 2208 Basic stats: COMPLETE Column stats: NONE
@@ -419,6 +422,7 @@ STAGE PLANS:
               Group By Operator
                 aggregations: sum(VALUE._col0)
                 keys: KEY._col0 (type: string), KEY._col1 (type: string), 0L (type: bigint)
+                grouping sets: 0, 1, 2, 3
                 mode: partials
                 outputColumnNames: _col0, _col1, _col2, _col3
                 Statistics: Num rows: 12 Data size: 2232 Basic stats: COMPLETE Column stats: COMPLETE
diff --git a/ql/src/test/results/clientpositive/llap/groupby_grouping_sets3.q.out b/ql/src/test/results/clientpositive/llap/groupby_grouping_sets3.q.out
index 6499199..e20b023 100644
--- a/ql/src/test/results/clientpositive/llap/groupby_grouping_sets3.q.out
+++ b/ql/src/test/results/clientpositive/llap/groupby_grouping_sets3.q.out
@@ -57,6 +57,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: sum(c), count(c), count()
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5
@@ -133,6 +134,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: sum(c), count(c), count()
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5
@@ -254,6 +256,7 @@ STAGE PLANS:
               Group By Operator
                 aggregations: sum(VALUE._col0), count(VALUE._col1), count(VALUE._col2)
                 keys: KEY._col0 (type: string), KEY._col1 (type: string), 0L (type: bigint)
+                grouping sets: 0, 1, 2, 3
                 mode: partials
                 outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5
                 Statistics: Num rows: 4 Data size: 2208 Basic stats: COMPLETE Column stats: NONE
diff --git a/ql/src/test/results/clientpositive/llap/groupby_grouping_sets4.q.out b/ql/src/test/results/clientpositive/llap/groupby_grouping_sets4.q.out
index e278bc6..c986abe 100644
--- a/ql/src/test/results/clientpositive/llap/groupby_grouping_sets4.q.out
+++ b/ql/src/test/results/clientpositive/llap/groupby_grouping_sets4.q.out
@@ -58,6 +58,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count()
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -195,6 +196,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count()
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -381,6 +383,7 @@ STAGE PLANS:
               Group By Operator
                 aggregations: count(VALUE._col0)
                 keys: KEY._col0 (type: string), KEY._col1 (type: string), 0L (type: bigint)
+                grouping sets: 0, 1, 2, 3
                 mode: partials
                 outputColumnNames: _col0, _col1, _col2, _col3
                 Statistics: Num rows: 4 Data size: 1472 Basic stats: COMPLETE Column stats: NONE
diff --git a/ql/src/test/results/clientpositive/llap/groupby_grouping_sets5.q.out b/ql/src/test/results/clientpositive/llap/groupby_grouping_sets5.q.out
index df4a872..5ff81a8 100644
--- a/ql/src/test/results/clientpositive/llap/groupby_grouping_sets5.q.out
+++ b/ql/src/test/results/clientpositive/llap/groupby_grouping_sets5.q.out
@@ -73,6 +73,7 @@ STAGE PLANS:
                 Group By Operator
                   aggregations: count()
                   keys: _col0 (type: string), _col1 (type: string), 0L (type: bigint)
+                  grouping sets: 0, 1, 2, 3
                   minReductionHashAggr: 0.99
                   mode: hash
                   outputColumnNames: _col0, _col1, _col2, _col3
@@ -171,6 +172,7 @@ STAGE PLANS:
                 Group By Operator
                   aggregations: count()
                   keys: _col0 (type: string), _col1 (type: string), 0L (type: bigint)
+                  grouping sets: 0, 1, 2, 3
                   minReductionHashAggr: 0.99
                   mode: hash
                   outputColumnNames: _col0, _col1, _col2, _col3
@@ -312,6 +314,7 @@ STAGE PLANS:
               Group By Operator
                 aggregations: count(VALUE._col0)
                 keys: KEY._col0 (type: string), KEY._col1 (type: string), 0L (type: bigint)
+                grouping sets: 0, 1, 2, 3
                 mode: partials
                 outputColumnNames: _col0, _col1, _col2, _col3
                 Statistics: Num rows: 4 Data size: 1472 Basic stats: COMPLETE Column stats: NONE
diff --git a/ql/src/test/results/clientpositive/llap/groupby_grouping_sets6.q.out b/ql/src/test/results/clientpositive/llap/groupby_grouping_sets6.q.out
index 4cd28c6..c997cae 100644
--- a/ql/src/test/results/clientpositive/llap/groupby_grouping_sets6.q.out
+++ b/ql/src/test/results/clientpositive/llap/groupby_grouping_sets6.q.out
@@ -50,6 +50,7 @@ STAGE PLANS:
                     Statistics: Num rows: 1 Data size: 368 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -135,6 +136,7 @@ STAGE PLANS:
                     Statistics: Num rows: 1 Data size: 368 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
diff --git a/ql/src/test/results/clientpositive/llap/groupby_grouping_sets_grouping.q.out b/ql/src/test/results/clientpositive/llap/groupby_grouping_sets_grouping.q.out
index 06b6262..9eed6cd 100644
--- a/ql/src/test/results/clientpositive/llap/groupby_grouping_sets_grouping.q.out
+++ b/ql/src/test/results/clientpositive/llap/groupby_grouping_sets_grouping.q.out
@@ -51,6 +51,7 @@ STAGE PLANS:
                     Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -149,6 +150,7 @@ STAGE PLANS:
                     Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -254,6 +256,7 @@ STAGE PLANS:
                     Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -357,6 +360,7 @@ STAGE PLANS:
                     Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -474,6 +478,7 @@ STAGE PLANS:
                     Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: key (type: int), value (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -572,6 +577,7 @@ STAGE PLANS:
                     Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: key (type: int), value (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -677,6 +683,7 @@ STAGE PLANS:
                     Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: key (type: int), value (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -777,6 +784,7 @@ STAGE PLANS:
                     Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: key (type: int), value (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1173,6 +1181,7 @@ STAGE PLANS:
                     Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: key (type: int), value (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1276,6 +1285,7 @@ STAGE PLANS:
                     Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: key (type: int), value (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1379,6 +1389,7 @@ STAGE PLANS:
                     Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: key (type: int), value (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1477,6 +1488,7 @@ STAGE PLANS:
                     Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: NONE
                     Group By Operator
                       keys: key (type: int), value (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
diff --git a/ql/src/test/results/clientpositive/llap/groupby_grouping_sets_limit.q.out b/ql/src/test/results/clientpositive/llap/groupby_grouping_sets_limit.q.out
index 47a537e..c1ad398 100644
--- a/ql/src/test/results/clientpositive/llap/groupby_grouping_sets_limit.q.out
+++ b/ql/src/test/results/clientpositive/llap/groupby_grouping_sets_limit.q.out
@@ -55,6 +55,7 @@ STAGE PLANS:
                       Group By Operator
                         aggregations: count()
                         keys: _col0 (type: string), _col1 (type: string), 0L (type: bigint)
+                        grouping sets: 0, 1, 2, 3
                         minReductionHashAggr: 0.99
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2, _col3
@@ -170,6 +171,7 @@ STAGE PLANS:
                       Group By Operator
                         aggregations: count()
                         keys: _col0 (type: string), _col1 (type: string), 0L (type: bigint)
+                        grouping sets: 0, 1, 2, 3
                         minReductionHashAggr: 0.99
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2, _col3
@@ -285,6 +287,7 @@ STAGE PLANS:
                       Group By Operator
                         aggregations: count()
                         keys: _col0 (type: string), _col1 (type: string), 0L (type: bigint)
+                        grouping sets: 0, 1
                         minReductionHashAggr: 0.99
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2, _col3
@@ -399,6 +402,7 @@ STAGE PLANS:
                       Statistics: Num rows: 1 Data size: 552 Basic stats: COMPLETE Column stats: NONE
                       Group By Operator
                         keys: _col0 (type: string), _col1 (type: string), _col2 (type: string), 0L (type: bigint)
+                        grouping sets: 3, 5, 6
                         minReductionHashAggr: 0.99
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/groupby_grouping_sets_pushdown1.q.out b/ql/src/test/results/clientpositive/llap/groupby_grouping_sets_pushdown1.q.out
index 6d393e2..21dbd52 100644
--- a/ql/src/test/results/clientpositive/llap/groupby_grouping_sets_pushdown1.q.out
+++ b/ql/src/test/results/clientpositive/llap/groupby_grouping_sets_pushdown1.q.out
@@ -58,6 +58,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: sum(s)
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 3, 1, 2, 0
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -204,6 +205,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: sum(s)
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 1, 0
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -348,6 +350,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: sum(s)
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 1, 0
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -499,6 +502,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: sum(s)
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 1, 0
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -685,6 +689,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: sum(s)
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 1, 0
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -842,6 +847,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: sum(s)
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 1, 0
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -994,6 +1000,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: sum(s)
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 3, 1, 0
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -1158,6 +1165,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: sum(s)
                       keys: upper(a) (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 1, 0
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -1322,6 +1330,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: sum(s)
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 2, 0
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/groupby_grouping_window.q.out b/ql/src/test/results/clientpositive/llap/groupby_grouping_window.q.out
index 3434d47..dacf0fa 100644
--- a/ql/src/test/results/clientpositive/llap/groupby_grouping_window.q.out
+++ b/ql/src/test/results/clientpositive/llap/groupby_grouping_window.q.out
@@ -60,6 +60,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: max(live), max(comments)
                       keys: category (type: int), 0L (type: bigint)
+                      grouping sets: 1, 0
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/groupby_rollup1.q.out b/ql/src/test/results/clientpositive/llap/groupby_rollup1.q.out
index 87d6bc0..d294cd7 100644
--- a/ql/src/test/results/clientpositive/llap/groupby_rollup1.q.out
+++ b/ql/src/test/results/clientpositive/llap/groupby_rollup1.q.out
@@ -48,6 +48,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count()
                       keys: key (type: string), val (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -143,6 +144,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count(DISTINCT val)
                       keys: key (type: string), 0L (type: bigint), val (type: string)
+                      grouping sets: 0, 1
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -232,6 +234,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count()
                       keys: key (type: string), val (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -344,6 +347,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count(DISTINCT val)
                       keys: key (type: string), 0L (type: bigint), val (type: string)
+                      grouping sets: 0, 1
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -479,6 +483,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count(1)
                       keys: key (type: string), val (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -497,6 +502,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: sum(1)
                       keys: key (type: string), val (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/groupby_rollup_empty.q.out b/ql/src/test/results/clientpositive/llap/groupby_rollup_empty.q.out
index cb2e90b..6931274 100644
--- a/ql/src/test/results/clientpositive/llap/groupby_rollup_empty.q.out
+++ b/ql/src/test/results/clientpositive/llap/groupby_rollup_empty.q.out
@@ -181,6 +181,7 @@ STAGE PLANS:
                       Group By Operator
                         aggregations: sum(_col2)
                         keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                        grouping sets: 1, 2, 3
                         minReductionHashAggr: 0.99
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/groupby_rollup_empty2.q.out b/ql/src/test/results/clientpositive/llap/groupby_rollup_empty2.q.out
index 900b16f..e15679d 100644
--- a/ql/src/test/results/clientpositive/llap/groupby_rollup_empty2.q.out
+++ b/ql/src/test/results/clientpositive/llap/groupby_rollup_empty2.q.out
@@ -154,6 +154,7 @@ STAGE PLANS:
                         Statistics: Num rows: 10 Data size: 900 Basic stats: COMPLETE Column stats: COMPLETE
                         Group By Operator
                           keys: _col0 (type: int), _col1 (type: string), 0L (type: bigint)
+                          grouping sets: 0, 1, 3
                           minReductionHashAggr: 0.19999999
                           mode: hash
                           outputColumnNames: _col0, _col1, _col2
diff --git a/ql/src/test/results/clientpositive/llap/infer_bucket_sort_grouping_operators.q.out b/ql/src/test/results/clientpositive/llap/infer_bucket_sort_grouping_operators.q.out
index 48f6355..067a827 100644
--- a/ql/src/test/results/clientpositive/llap/infer_bucket_sort_grouping_operators.q.out
+++ b/ql/src/test/results/clientpositive/llap/infer_bucket_sort_grouping_operators.q.out
@@ -51,6 +51,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count()
                       keys: key (type: string), value (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -1543,6 +1544,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count()
                       keys: key (type: string), value (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -1781,6 +1783,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count()
                       keys: key (type: string), value (type: string), 0L (type: bigint)
+                      grouping sets: 1, 2
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/join18_multi_distinct.q.out b/ql/src/test/results/clientpositive/llap/join18_multi_distinct.q.out
index 4d83d96..991bec6 100644
--- a/ql/src/test/results/clientpositive/llap/join18_multi_distinct.q.out
+++ b/ql/src/test/results/clientpositive/llap/join18_multi_distinct.q.out
@@ -82,6 +82,7 @@ STAGE PLANS:
                     Statistics: Num rows: 25 Data size: 4375 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: _col0 (type: string), _col1 (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
diff --git a/ql/src/test/results/clientpositive/llap/limit_pushdown.q.out b/ql/src/test/results/clientpositive/llap/limit_pushdown.q.out
index 2227dc3..da169a1 100644
--- a/ql/src/test/results/clientpositive/llap/limit_pushdown.q.out
+++ b/ql/src/test/results/clientpositive/llap/limit_pushdown.q.out
@@ -785,6 +785,7 @@ STAGE PLANS:
                       Statistics: Num rows: 12288 Data size: 1779850 Basic stats: COMPLETE Column stats: COMPLETE
                       Group By Operator
                         keys: _col0 (type: tinyint), _col1 (type: string), _col2 (type: string), 0L (type: bigint)
+                        grouping sets: 1, 2
                         minReductionHashAggr: 0.0
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/limit_pushdown2.q.out b/ql/src/test/results/clientpositive/llap/limit_pushdown2.q.out
index 8838c68..e8a947f 100644
--- a/ql/src/test/results/clientpositive/llap/limit_pushdown2.q.out
+++ b/ql/src/test/results/clientpositive/llap/limit_pushdown2.q.out
@@ -1151,6 +1151,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: sum(_col2), count(_col2)
                       keys: _col0 (type: string), _col1 (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3, _col4
@@ -1253,6 +1254,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: sum(_col2), count(_col2)
                       keys: _col0 (type: string), _col1 (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3, _col4
diff --git a/ql/src/test/results/clientpositive/llap/limit_pushdown3.q.out b/ql/src/test/results/clientpositive/llap/limit_pushdown3.q.out
index 7b311c2..c4da76b 100644
--- a/ql/src/test/results/clientpositive/llap/limit_pushdown3.q.out
+++ b/ql/src/test/results/clientpositive/llap/limit_pushdown3.q.out
@@ -843,6 +843,7 @@ STAGE PLANS:
                       Statistics: Num rows: 12288 Data size: 1779850 Basic stats: COMPLETE Column stats: COMPLETE
                       Group By Operator
                         keys: _col0 (type: tinyint), _col1 (type: string), _col2 (type: string), 0L (type: bigint)
+                        grouping sets: 1, 2
                         minReductionHashAggr: 0.0
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/multi_count_distinct_null.q.out b/ql/src/test/results/clientpositive/llap/multi_count_distinct_null.q.out
index 3aad239..0d71efd 100644
--- a/ql/src/test/results/clientpositive/llap/multi_count_distinct_null.q.out
+++ b/ql/src/test/results/clientpositive/llap/multi_count_distinct_null.q.out
@@ -53,6 +53,7 @@ STAGE PLANS:
                     Statistics: Num rows: 12 Data size: 1023 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: _col0 (type: int), _col1 (type: varchar(10)), _col2 (type: int), 0L (type: bigint)
+                      grouping sets: 3, 5, 6
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -202,6 +203,7 @@ STAGE PLANS:
                     Statistics: Num rows: 12 Data size: 1023 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: _col0 (type: varchar(10)), _col1 (type: int), _col2 (type: int), 0L (type: bigint)
+                      grouping sets: 0, 3, 4, 5, 6
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/offset_limit_ppd_optimizer.q.out b/ql/src/test/results/clientpositive/llap/offset_limit_ppd_optimizer.q.out
index cfb17ce..dc0a52f 100644
--- a/ql/src/test/results/clientpositive/llap/offset_limit_ppd_optimizer.q.out
+++ b/ql/src/test/results/clientpositive/llap/offset_limit_ppd_optimizer.q.out
@@ -792,6 +792,7 @@ STAGE PLANS:
                       Statistics: Num rows: 12288 Data size: 1779850 Basic stats: COMPLETE Column stats: COMPLETE
                       Group By Operator
                         keys: _col0 (type: tinyint), _col1 (type: string), _col2 (type: string), 0L (type: bigint)
+                        grouping sets: 1, 2
                         minReductionHashAggr: 0.0
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/reduce_deduplicate_distinct.q.out b/ql/src/test/results/clientpositive/llap/reduce_deduplicate_distinct.q.out
index fa2a67f..b70b703 100644
--- a/ql/src/test/results/clientpositive/llap/reduce_deduplicate_distinct.q.out
+++ b/ql/src/test/results/clientpositive/llap/reduce_deduplicate_distinct.q.out
@@ -52,6 +52,7 @@ STAGE PLANS:
                     Statistics: Num rows: 5 Data size: 60 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: _col0 (type: int), _col1 (type: int), _col2 (type: int), 0L (type: bigint)
+                      grouping sets: 1, 2
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -167,6 +168,7 @@ STAGE PLANS:
                 Statistics: Num rows: 2 Data size: 24 Basic stats: COMPLETE Column stats: COMPLETE
                 Group By Operator
                   keys: _col0 (type: int), _col1 (type: int), _col2 (type: int), 0L (type: bigint)
+                  grouping sets: 1, 2
                   minReductionHashAggr: 0.0
                   mode: hash
                   outputColumnNames: _col0, _col1, _col2, _col3
@@ -280,6 +282,7 @@ STAGE PLANS:
                 Statistics: Num rows: 2 Data size: 24 Basic stats: COMPLETE Column stats: COMPLETE
                 Group By Operator
                   keys: _col0 (type: int), _col1 (type: int), _col2 (type: int), 0L (type: bigint)
+                  grouping sets: 1, 2
                   minReductionHashAggr: 0.0
                   mode: hash
                   outputColumnNames: _col0, _col1, _col2, _col3
@@ -394,6 +397,7 @@ STAGE PLANS:
                 Statistics: Num rows: 2 Data size: 24 Basic stats: COMPLETE Column stats: COMPLETE
                 Group By Operator
                   keys: _col0 (type: int), _col1 (type: int), _col2 (type: int), 0L (type: bigint)
+                  grouping sets: 1, 2
                   minReductionHashAggr: 0.0
                   mode: hash
                   outputColumnNames: _col0, _col1, _col2, _col3
@@ -525,6 +529,7 @@ STAGE PLANS:
                 Statistics: Num rows: 2 Data size: 24 Basic stats: COMPLETE Column stats: COMPLETE
                 Group By Operator
                   keys: _col0 (type: int), _col1 (type: int), _col2 (type: int), 0L (type: bigint)
+                  grouping sets: 1, 2
                   minReductionHashAggr: 0.0
                   mode: hash
                   outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/topnkey_grouping_sets.q.out b/ql/src/test/results/clientpositive/llap/topnkey_grouping_sets.q.out
index c11b030..7c28aec 100644
--- a/ql/src/test/results/clientpositive/llap/topnkey_grouping_sets.q.out
+++ b/ql/src/test/results/clientpositive/llap/topnkey_grouping_sets.q.out
@@ -83,6 +83,7 @@ STAGE PLANS:
                       Statistics: Num rows: 13 Data size: 80 Basic stats: COMPLETE Column stats: COMPLETE
                       Group By Operator
                         keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                        grouping sets: 0, 1, 2, 3
                         minReductionHashAggr: 0.15384614
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2
@@ -199,6 +200,7 @@ STAGE PLANS:
                       Statistics: Num rows: 13 Data size: 80 Basic stats: COMPLETE Column stats: COMPLETE
                       Group By Operator
                         keys: a (type: int), b (type: int), 0L (type: bigint)
+                        grouping sets: 0, 1, 2, 3
                         minReductionHashAggr: 0.15384614
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2
@@ -319,6 +321,7 @@ STAGE PLANS:
                     Statistics: Num rows: 13 Data size: 80 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: a (type: int), b (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.15384614
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -431,6 +434,7 @@ STAGE PLANS:
                     Statistics: Num rows: 13 Data size: 80 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: a (type: int), b (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.15384614
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -539,6 +543,7 @@ STAGE PLANS:
                     Statistics: Num rows: 13 Data size: 80 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: a (type: int), b (type: int), 0L (type: bigint)
+                      grouping sets: 1, 2
                       minReductionHashAggr: 0.15384614
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -665,6 +670,7 @@ STAGE PLANS:
                       Statistics: Num rows: 13 Data size: 80 Basic stats: COMPLETE Column stats: COMPLETE
                       Group By Operator
                         keys: a (type: int), b (type: int), 0L (type: bigint)
+                        grouping sets: 0, 1
                         minReductionHashAggr: 0.15384614
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2
@@ -785,6 +791,7 @@ STAGE PLANS:
                       Statistics: Num rows: 13 Data size: 80 Basic stats: COMPLETE Column stats: COMPLETE
                       Group By Operator
                         keys: a (type: int), b (type: int), 0L (type: bigint)
+                        grouping sets: 0, 2
                         minReductionHashAggr: 0.15384614
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2
@@ -905,6 +912,7 @@ STAGE PLANS:
                       Statistics: Num rows: 13 Data size: 80 Basic stats: COMPLETE Column stats: COMPLETE
                       Group By Operator
                         keys: a (type: int), b (type: int), 0L (type: bigint)
+                        grouping sets: 0, 3
                         minReductionHashAggr: 0.15384614
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2
@@ -1025,6 +1033,7 @@ STAGE PLANS:
                       Statistics: Num rows: 13 Data size: 80 Basic stats: COMPLETE Column stats: COMPLETE
                       Group By Operator
                         keys: a (type: int), b (type: int), 0L (type: bigint)
+                        grouping sets: 0, 3
                         minReductionHashAggr: 0.15384614
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2
@@ -1173,6 +1182,7 @@ STAGE PLANS:
                   Group By Operator
                     aggregations: max(_col2)
                     keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                    grouping sets: 0, 3
                     minReductionHashAggr: 0.0
                     mode: hash
                     outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/topnkey_grouping_sets_functions.q.out b/ql/src/test/results/clientpositive/llap/topnkey_grouping_sets_functions.q.out
index b0e4193..d5e0762 100644
--- a/ql/src/test/results/clientpositive/llap/topnkey_grouping_sets_functions.q.out
+++ b/ql/src/test/results/clientpositive/llap/topnkey_grouping_sets_functions.q.out
@@ -78,6 +78,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: sum(c)
                       keys: a (type: int), b (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.15384614
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -206,6 +207,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: min(c)
                       keys: a (type: int), b (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.15384614
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -334,6 +336,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: max(c)
                       keys: a (type: int), b (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.15384614
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/topnkey_grouping_sets_order.q.out b/ql/src/test/results/clientpositive/llap/topnkey_grouping_sets_order.q.out
index a13c3b3..0590e5a 100644
--- a/ql/src/test/results/clientpositive/llap/topnkey_grouping_sets_order.q.out
+++ b/ql/src/test/results/clientpositive/llap/topnkey_grouping_sets_order.q.out
@@ -77,6 +77,7 @@ STAGE PLANS:
                     Statistics: Num rows: 13 Data size: 80 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: a (type: int), b (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.15384614
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -197,6 +198,7 @@ STAGE PLANS:
                     Statistics: Num rows: 13 Data size: 80 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: a (type: int), b (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.15384614
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -323,6 +325,7 @@ STAGE PLANS:
                       Statistics: Num rows: 13 Data size: 80 Basic stats: COMPLETE Column stats: COMPLETE
                       Group By Operator
                         keys: a (type: int), b (type: int), 0L (type: bigint)
+                        grouping sets: 0, 1, 2, 3
                         minReductionHashAggr: 0.15384614
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2
@@ -443,6 +446,7 @@ STAGE PLANS:
                       Statistics: Num rows: 13 Data size: 80 Basic stats: COMPLETE Column stats: COMPLETE
                       Group By Operator
                         keys: a (type: int), b (type: int), 0L (type: bigint)
+                        grouping sets: 0, 1, 2, 3
                         minReductionHashAggr: 0.15384614
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2
diff --git a/ql/src/test/results/clientpositive/llap/vector_groupby_cube1.q.out b/ql/src/test/results/clientpositive/llap/vector_groupby_cube1.q.out
index f1fdda5..51c6767 100644
--- a/ql/src/test/results/clientpositive/llap/vector_groupby_cube1.q.out
+++ b/ql/src/test/results/clientpositive/llap/vector_groupby_cube1.q.out
@@ -67,6 +67,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0]
                       keys: key (type: string), val (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -210,6 +211,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0]
                       keys: key (type: string), val (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -379,6 +381,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0]
                       keys: _col0 (type: string), _col1 (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -532,6 +535,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count(DISTINCT val)
                       keys: key (type: string), 0L (type: bigint), val (type: string)
+                      grouping sets: 0, 1
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -651,6 +655,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0]
                       keys: key (type: string), val (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -851,6 +856,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count(DISTINCT val)
                       keys: key (type: string), 0L (type: bigint), val (type: string)
+                      grouping sets: 0, 1
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -1021,6 +1027,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0]
                       keys: key (type: string), val (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -1058,6 +1065,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0]
                       keys: key (type: string), val (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_id1.q.out b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_id1.q.out
index 480011e..fd8adca 100644
--- a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_id1.q.out
+++ b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_id1.q.out
@@ -79,6 +79,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: _col0 (type: string), _col1 (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -243,6 +244,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: _col0 (type: string), _col1 (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -407,6 +409,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: _col0 (type: string), _col1 (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -565,6 +568,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: _col0 (type: string), _col1 (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -723,6 +727,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: _col0 (type: string), _col1 (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -888,6 +893,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: _col0 (type: string), _col1 (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
diff --git a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_id2.q.out b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_id2.q.out
index bf610a6..0bd9b34 100644
--- a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_id2.q.out
+++ b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_id2.q.out
@@ -82,6 +82,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0]
                       keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -291,6 +292,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0]
                       keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -510,6 +512,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -825,6 +828,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1136,6 +1140,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1472,6 +1477,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1801,6 +1807,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0]
                       keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -1973,6 +1980,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -2198,6 +2206,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
diff --git a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_id3.q.out b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_id3.q.out
index 554cabb..9a426fa 100644
--- a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_id3.q.out
+++ b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_id3.q.out
@@ -89,6 +89,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0]
                       keys: key (type: int), value (type: int), 0L (type: bigint)
+                      grouping sets: 3, 1
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -271,6 +272,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0]
                       keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                      grouping sets: 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets1.q.out b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets1.q.out
index 4d2dee4..a5ce1e2 100644
--- a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets1.q.out
+++ b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets1.q.out
@@ -97,6 +97,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0]
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -265,6 +266,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0]
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -433,6 +435,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0]
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -601,6 +604,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0]
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -763,6 +767,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: a (type: string), b (type: string), c (type: string), 0L (type: bigint)
+                      grouping sets: 3, 5, 6
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets2.q.out b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets2.q.out
index c6587d1..c1191aa 100644
--- a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets2.q.out
+++ b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets2.q.out
@@ -144,6 +144,7 @@ STAGE PLANS:
                     vectorProcessingMode: STREAMING
                     projectedOutputColumnNums: [0]
                 keys: KEY._col0 (type: string), KEY._col1 (type: string), 0L (type: bigint)
+                grouping sets: 0, 1, 2, 3
                 mode: partials
                 outputColumnNames: _col0, _col1, _col2, _col3
                 Statistics: Num rows: 12 Data size: 2232 Basic stats: COMPLETE Column stats: COMPLETE
@@ -332,6 +333,7 @@ STAGE PLANS:
                     vectorProcessingMode: STREAMING
                     projectedOutputColumnNums: [0]
                 keys: KEY._col0 (type: string), KEY._col1 (type: string), 0L (type: bigint)
+                grouping sets: 0, 1, 2, 3
                 mode: partials
                 outputColumnNames: _col0, _col1, _col2, _col3
                 Statistics: Num rows: 12 Data size: 2232 Basic stats: COMPLETE Column stats: COMPLETE
@@ -514,6 +516,7 @@ STAGE PLANS:
                     vectorProcessingMode: STREAMING
                     projectedOutputColumnNums: [0]
                 keys: KEY._col0 (type: string), KEY._col1 (type: string), 0L (type: bigint)
+                grouping sets: 0, 1, 2, 3
                 mode: partials
                 outputColumnNames: _col0, _col1, _col2, _col3
                 Statistics: Num rows: 12 Data size: 2232 Basic stats: COMPLETE Column stats: COMPLETE
@@ -750,6 +753,7 @@ STAGE PLANS:
                     vectorProcessingMode: STREAMING
                     projectedOutputColumnNums: [0]
                 keys: KEY._col0 (type: string), KEY._col1 (type: string), 0L (type: bigint)
+                grouping sets: 0, 1, 2, 3
                 mode: partials
                 outputColumnNames: _col0, _col1, _col2, _col3
                 Statistics: Num rows: 12 Data size: 2232 Basic stats: COMPLETE Column stats: COMPLETE
diff --git a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets3.q.out b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets3.q.out
index 50921a2..6f22942 100644
--- a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets3.q.out
+++ b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets3.q.out
@@ -75,6 +75,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: sum(c), count(c), count()
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.3333333
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5
@@ -190,6 +191,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: sum(c), count(c), count()
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.3333333
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5
@@ -377,6 +379,7 @@ STAGE PLANS:
                     vectorProcessingMode: STREAMING
                     projectedOutputColumnNums: [0, 1, 2]
                 keys: KEY._col0 (type: string), KEY._col1 (type: string), 0L (type: bigint)
+                grouping sets: 0, 1, 2, 3
                 mode: partials
                 outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5
                 Statistics: Num rows: 24 Data size: 4848 Basic stats: COMPLETE Column stats: COMPLETE
diff --git a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets3_dec.q.out b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets3_dec.q.out
index 3c79f3e..6a1119d 100644
--- a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets3_dec.q.out
+++ b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets3_dec.q.out
@@ -90,6 +90,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0, 1, 2]
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.3333333
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5
@@ -235,6 +236,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0, 1, 2]
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.3333333
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5
@@ -467,6 +469,7 @@ STAGE PLANS:
                     vectorProcessingMode: STREAMING
                     projectedOutputColumnNums: [0, 1, 2]
                 keys: KEY._col0 (type: string), KEY._col1 (type: string), 0L (type: bigint)
+                grouping sets: 0, 1, 2, 3
                 mode: partials
                 outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5
                 Statistics: Num rows: 24 Data size: 7344 Basic stats: COMPLETE Column stats: COMPLETE
diff --git a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets4.q.out b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets4.q.out
index 95617f4..8b36935 100644
--- a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets4.q.out
+++ b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets4.q.out
@@ -92,6 +92,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0]
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -349,6 +350,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0]
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -698,6 +700,7 @@ STAGE PLANS:
                     vectorProcessingMode: STREAMING
                     projectedOutputColumnNums: [0]
                 keys: KEY._col0 (type: string), KEY._col1 (type: string), 0L (type: bigint)
+                grouping sets: 0, 1, 2, 3
                 mode: partials
                 outputColumnNames: _col0, _col1, _col2, _col3
                 Statistics: Num rows: 4 Data size: 744 Basic stats: COMPLETE Column stats: COMPLETE
diff --git a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets5.q.out b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets5.q.out
index dafe07d..683dc47 100644
--- a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets5.q.out
+++ b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets5.q.out
@@ -154,6 +154,7 @@ STAGE PLANS:
                       vectorProcessingMode: HASH
                       projectedOutputColumnNums: [0]
                   keys: _col0 (type: string), _col1 (type: string), 0L (type: bigint)
+                  grouping sets: 0, 1, 2, 3
                   minReductionHashAggr: 0.0
                   mode: hash
                   outputColumnNames: _col0, _col1, _col2, _col3
@@ -353,6 +354,7 @@ STAGE PLANS:
                       vectorProcessingMode: HASH
                       projectedOutputColumnNums: [0]
                   keys: _col0 (type: string), _col1 (type: string), 0L (type: bigint)
+                  grouping sets: 0, 1, 2, 3
                   minReductionHashAggr: 0.0
                   mode: hash
                   outputColumnNames: _col0, _col1, _col2, _col3
@@ -623,6 +625,7 @@ STAGE PLANS:
                     vectorProcessingMode: STREAMING
                     projectedOutputColumnNums: [0]
                 keys: KEY._col0 (type: string), KEY._col1 (type: string), 0L (type: bigint)
+                grouping sets: 0, 1, 2, 3
                 mode: partials
                 outputColumnNames: _col0, _col1, _col2, _col3
                 Statistics: Num rows: 4 Data size: 744 Basic stats: COMPLETE Column stats: COMPLETE
diff --git a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets6.q.out b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets6.q.out
index 8a1ba0a..37bb58a 100644
--- a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets6.q.out
+++ b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets6.q.out
@@ -83,6 +83,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -231,6 +232,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: a (type: string), b (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
diff --git a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets_grouping.q.out b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets_grouping.q.out
index 9a96c0c..b2102cc 100644
--- a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets_grouping.q.out
+++ b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets_grouping.q.out
@@ -83,6 +83,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -249,6 +250,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -422,6 +424,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -596,6 +599,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: _col0 (type: int), _col1 (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -808,6 +812,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: key (type: int), value (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -974,6 +979,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: key (type: int), value (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1147,6 +1153,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: key (type: int), value (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -1314,6 +1321,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: key (type: int), value (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -2005,6 +2013,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: key (type: int), value (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -2176,6 +2185,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: key (type: int), value (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 2, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -2347,6 +2357,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: key (type: int), value (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
@@ -2513,6 +2524,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: key (type: int), value (type: int), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2
diff --git a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets_limit.q.out b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets_limit.q.out
index fb0170c..dd202ba 100644
--- a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets_limit.q.out
+++ b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_sets_limit.q.out
@@ -93,6 +93,7 @@ STAGE PLANS:
                             vectorProcessingMode: HASH
                             projectedOutputColumnNums: [0]
                         keys: a (type: string), b (type: string), 0L (type: bigint)
+                        grouping sets: 0, 1, 2, 3
                         minReductionHashAggr: 0.0
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2, _col3
@@ -309,6 +310,7 @@ STAGE PLANS:
                             vectorProcessingMode: HASH
                             projectedOutputColumnNums: [0]
                         keys: a (type: string), b (type: string), 0L (type: bigint)
+                        grouping sets: 0, 1, 2, 3
                         minReductionHashAggr: 0.0
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2, _col3
@@ -525,6 +527,7 @@ STAGE PLANS:
                             vectorProcessingMode: HASH
                             projectedOutputColumnNums: [0]
                         keys: a (type: string), b (type: string), 0L (type: bigint)
+                        grouping sets: 0, 1
                         minReductionHashAggr: 0.0
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2, _col3
@@ -739,6 +742,7 @@ STAGE PLANS:
                             vectorProcessingMode: HASH
                             projectedOutputColumnNums: []
                         keys: a (type: string), b (type: string), c (type: string), 0L (type: bigint)
+                        grouping sets: 3, 5, 6
                         minReductionHashAggr: 0.0
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_window.q.out b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_window.q.out
index 9118226..874e44e 100644
--- a/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_window.q.out
+++ b/ql/src/test/results/clientpositive/llap/vector_groupby_grouping_window.q.out
@@ -81,6 +81,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0, 1]
                       keys: category (type: int), 0L (type: bigint)
+                      grouping sets: 1, 0
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/vector_groupby_rollup1.q.out b/ql/src/test/results/clientpositive/llap/vector_groupby_rollup1.q.out
index e6ae542..37efb83 100644
--- a/ql/src/test/results/clientpositive/llap/vector_groupby_rollup1.q.out
+++ b/ql/src/test/results/clientpositive/llap/vector_groupby_rollup1.q.out
@@ -79,6 +79,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0]
                       keys: key (type: string), val (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -227,6 +228,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count(DISTINCT val)
                       keys: key (type: string), 0L (type: bigint), val (type: string)
+                      grouping sets: 0, 1
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -346,6 +348,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0]
                       keys: key (type: string), val (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -540,6 +543,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: count(DISTINCT val)
                       keys: key (type: string), 0L (type: bigint), val (type: string)
+                      grouping sets: 0, 1
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -708,6 +712,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0]
                       keys: key (type: string), val (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
@@ -745,6 +750,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: [0]
                       keys: key (type: string), val (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.99
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3
diff --git a/ql/src/test/results/clientpositive/llap/vector_grouping_sets.q.out b/ql/src/test/results/clientpositive/llap/vector_grouping_sets.q.out
index e4de69a..283f1bc 100644
--- a/ql/src/test/results/clientpositive/llap/vector_grouping_sets.q.out
+++ b/ql/src/test/results/clientpositive/llap/vector_grouping_sets.q.out
@@ -177,6 +177,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: s_store_id (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1
                       minReductionHashAggr: 0.5
                       mode: hash
                       outputColumnNames: _col0, _col1
@@ -314,6 +315,7 @@ STAGE PLANS:
                           vectorProcessingMode: HASH
                           projectedOutputColumnNums: []
                       keys: _col0 (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1
                       minReductionHashAggr: 0.5
                       mode: hash
                       outputColumnNames: _col0, _col1
@@ -441,6 +443,7 @@ STAGE PLANS:
                     Statistics: Num rows: 12 Data size: 1200 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: _col0 (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1
                       minReductionHashAggr: 0.5
                       mode: hash
                       outputColumnNames: _col0, _col1
diff --git a/ql/src/test/results/clientpositive/llap/view_cbo.q.out b/ql/src/test/results/clientpositive/llap/view_cbo.q.out
index 05e0d01..a9dcdee 100644
--- a/ql/src/test/results/clientpositive/llap/view_cbo.q.out
+++ b/ql/src/test/results/clientpositive/llap/view_cbo.q.out
@@ -37,6 +37,7 @@ STAGE PLANS:
                     Group By Operator
                       aggregations: sum(_col2), count(_col2)
                       keys: _col0 (type: string), _col1 (type: string), 0L (type: bigint)
+                      grouping sets: 0, 1, 3
                       minReductionHashAggr: 0.0
                       mode: hash
                       outputColumnNames: _col0, _col1, _col2, _col3, _col4
diff --git a/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query_grouping_sets.q.out b/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query_grouping_sets.q.out
new file mode 100644
index 0000000..71768cd
--- /dev/null
+++ b/ql/src/test/results/clientpositive/perf/tez/constraints/cbo_query_grouping_sets.q.out
@@ -0,0 +1,464 @@
+PREHOOK: query: EXPLAIN CBO
+select  
+        ca_country, ca_state, i_item_id,
+         avg( cast(cs_quantity as numeric(12,2))) agg1,
+         avg( cast(c_birth_year as numeric(12,2))) agg6,
+         avg( cast(cd1.cd_dep_count as numeric(12,2))) agg7
+from catalog_sales, customer_demographics cd1,
+        customer, customer_address,
+        date_dim,
+        item
+where cs_sold_date_sk = d_date_sk and
+        cs_item_sk = i_item_sk and
+        cs_bill_cdemo_sk = cd1.cd_demo_sk and
+        cs_bill_customer_sk = c_customer_sk and
+        cd1.cd_gender = 'M' and
+        cd1.cd_education_status = 'College' and
+        c_current_addr_sk = ca_address_sk and
+        c_birth_month in (9,5) and
+        d_year = 2001 and
+        ca_state in ('AL','MS','TN')
+group by rollup(i_item_id, ca_country, ca_state)
+order by ca_country, ca_state, i_item_id NULLS FIRST
+limit 100
+PREHOOK: type: QUERY
+PREHOOK: Input: default@catalog_sales
+PREHOOK: Input: default@customer
+PREHOOK: Input: default@customer_address
+PREHOOK: Input: default@customer_demographics
+PREHOOK: Input: default@date_dim
+PREHOOK: Input: default@item
+PREHOOK: Output: hdfs://### HDFS PATH ###
+POSTHOOK: query: EXPLAIN CBO
+select  
+        ca_country, ca_state, i_item_id,
+         avg( cast(cs_quantity as numeric(12,2))) agg1,
+         avg( cast(c_birth_year as numeric(12,2))) agg6,
+         avg( cast(cd1.cd_dep_count as numeric(12,2))) agg7
+from catalog_sales, customer_demographics cd1,
+        customer, customer_address,
+        date_dim,
+        item
+where cs_sold_date_sk = d_date_sk and
+        cs_item_sk = i_item_sk and
+        cs_bill_cdemo_sk = cd1.cd_demo_sk and
+        cs_bill_customer_sk = c_customer_sk and
+        cd1.cd_gender = 'M' and
+        cd1.cd_education_status = 'College' and
+        c_current_addr_sk = ca_address_sk and
+        c_birth_month in (9,5) and
+        d_year = 2001 and
+        ca_state in ('AL','MS','TN')
+group by rollup(i_item_id, ca_country, ca_state)
+order by ca_country, ca_state, i_item_id NULLS FIRST
+limit 100
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@catalog_sales
+POSTHOOK: Input: default@customer
+POSTHOOK: Input: default@customer_address
+POSTHOOK: Input: default@customer_demographics
+POSTHOOK: Input: default@date_dim
+POSTHOOK: Input: default@item
+POSTHOOK: Output: hdfs://### HDFS PATH ###
+CBO PLAN:
+HiveSortLimit(sort0=[$0], sort1=[$1], sort2=[$2], dir0=[ASC], dir1=[ASC], dir2=[ASC-nulls-first], fetch=[100])
+  HiveProject(ca_country=[$2], ca_state=[$1], i_item_id=[$0], agg1=[CAST(/($3, $4)):DECIMAL(16, 6)], agg6=[CAST(/($5, $6)):DECIMAL(16, 6)], agg7=[CAST(/($7, $8)):DECIMAL(16, 6)])
+    HiveAggregate(group=[{1, 6, 7}], groups=[[{1, 6, 7}, {1, 7}, {1}, {}]], agg#0=[sum($12)], agg#1=[count($12)], agg#2=[sum($4)], agg#3=[count($4)], agg#4=[sum($15)], agg#5=[count($15)])
+      HiveJoin(condition=[=($11, $0)], joinType=[inner], algorithm=[none], cost=[not available])
+        HiveProject(i_item_sk=[$0], i_item_id=[$1])
+          HiveTableScan(table=[[default, item]], table:alias=[item])
+        HiveJoin(condition=[=($7, $0)], joinType=[inner], algorithm=[none], cost=[not available])
+          HiveJoin(condition=[=($1, $3)], joinType=[inner], algorithm=[none], cost=[not available])
+            HiveProject(c_customer_sk=[$0], c_current_addr_sk=[$4], CAST=[CAST($13):DECIMAL(12, 2)])
+              HiveFilter(condition=[AND(IN($12, 9, 5), IS NOT NULL($4))])
+                HiveTableScan(table=[[default, customer]], table:alias=[customer])
+            HiveProject(ca_address_sk=[$0], ca_state=[$8], ca_country=[$10])
+              HiveFilter(condition=[IN($8, _UTF-16LE'AL':VARCHAR(2147483647) CHARACTER SET "UTF-16LE", _UTF-16LE'MS':VARCHAR(2147483647) CHARACTER SET "UTF-16LE", _UTF-16LE'TN':VARCHAR(2147483647) CHARACTER SET "UTF-16LE")])
+                HiveTableScan(table=[[default, customer_address]], table:alias=[customer_address])
+          HiveProject(cs_sold_date_sk=[$0], cs_bill_customer_sk=[$1], cs_bill_cdemo_sk=[$2], cs_item_sk=[$3], CAST=[$4], d_date_sk=[$5], cd_demo_sk=[$6], CAST0=[$7])
+            HiveJoin(condition=[=($2, $6)], joinType=[inner], algorithm=[none], cost=[not available])
+              HiveJoin(condition=[=($0, $5)], joinType=[inner], algorithm=[none], cost=[not available])
+                HiveProject(cs_sold_date_sk=[$0], cs_bill_customer_sk=[$3], cs_bill_cdemo_sk=[$4], cs_item_sk=[$15], CAST=[CAST($18):DECIMAL(12, 2)])
+                  HiveFilter(condition=[AND(IS NOT NULL($0), IS NOT NULL($4), IS NOT NULL($3))])
+                    HiveTableScan(table=[[default, catalog_sales]], table:alias=[catalog_sales])
+                HiveProject(d_date_sk=[$0])
+                  HiveFilter(condition=[=($6, 2001)])
+                    HiveTableScan(table=[[default, date_dim]], table:alias=[date_dim])
+              HiveProject(cd_demo_sk=[$0], CAST=[CAST($6):DECIMAL(12, 2)])
+                HiveFilter(condition=[AND(=($3, _UTF-16LE'College'), =($1, _UTF-16LE'M'))])
+                  HiveTableScan(table=[[default, customer_demographics]], table:alias=[cd1])
+
+PREHOOK: query: EXPLAIN
+select  
+        ca_country, ca_state, i_item_id,
+         avg( cast(cs_quantity as numeric(12,2))) agg1,
+         avg( cast(c_birth_year as numeric(12,2))) agg6,
+         avg( cast(cd1.cd_dep_count as numeric(12,2))) agg7
+from catalog_sales, customer_demographics cd1,
+        customer, customer_address,
+        date_dim,
+        item
+where cs_sold_date_sk = d_date_sk and
+        cs_item_sk = i_item_sk and
+        cs_bill_cdemo_sk = cd1.cd_demo_sk and
+        cs_bill_customer_sk = c_customer_sk and
+        cd1.cd_gender = 'M' and
+        cd1.cd_education_status = 'College' and
+        c_current_addr_sk = ca_address_sk and
+        c_birth_month in (9,5) and
+        d_year = 2001 and
+        ca_state in ('AL','MS','TN')
+group by rollup(i_item_id, ca_country, ca_state)
+order by ca_country, ca_state, i_item_id NULLS FIRST
+limit 100
+PREHOOK: type: QUERY
+PREHOOK: Input: default@catalog_sales
+PREHOOK: Input: default@customer
+PREHOOK: Input: default@customer_address
+PREHOOK: Input: default@customer_demographics
+PREHOOK: Input: default@date_dim
+PREHOOK: Input: default@item
+PREHOOK: Output: hdfs://### HDFS PATH ###
+POSTHOOK: query: EXPLAIN
+select  
+        ca_country, ca_state, i_item_id,
+         avg( cast(cs_quantity as numeric(12,2))) agg1,
+         avg( cast(c_birth_year as numeric(12,2))) agg6,
+         avg( cast(cd1.cd_dep_count as numeric(12,2))) agg7
+from catalog_sales, customer_demographics cd1,
+        customer, customer_address,
+        date_dim,
+        item
+where cs_sold_date_sk = d_date_sk and
+        cs_item_sk = i_item_sk and
+        cs_bill_cdemo_sk = cd1.cd_demo_sk and
+        cs_bill_customer_sk = c_customer_sk and
+        cd1.cd_gender = 'M' and
+        cd1.cd_education_status = 'College' and
+        c_current_addr_sk = ca_address_sk and
+        c_birth_month in (9,5) and
+        d_year = 2001 and
+        ca_state in ('AL','MS','TN')
+group by rollup(i_item_id, ca_country, ca_state)
+order by ca_country, ca_state, i_item_id NULLS FIRST
+limit 100
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@catalog_sales
+POSTHOOK: Input: default@customer
+POSTHOOK: Input: default@customer_address
+POSTHOOK: Input: default@customer_demographics
+POSTHOOK: Input: default@date_dim
+POSTHOOK: Input: default@item
+POSTHOOK: Output: hdfs://### HDFS PATH ###
+STAGE DEPENDENCIES:
+  Stage-1 is a root stage
+  Stage-0 depends on stages: Stage-1
+
+STAGE PLANS:
+  Stage: Stage-1
+    Tez
+#### A masked pattern was here ####
+      Edges:
+        Map 8 <- Reducer 12 (BROADCAST_EDGE)
+        Reducer 10 <- Map 13 (SIMPLE_EDGE), Reducer 9 (SIMPLE_EDGE)
+        Reducer 12 <- Map 11 (CUSTOM_SIMPLE_EDGE)
+        Reducer 2 <- Map 1 (SIMPLE_EDGE), Map 7 (SIMPLE_EDGE)
+        Reducer 3 <- Reducer 10 (SIMPLE_EDGE), Reducer 2 (SIMPLE_EDGE)
+        Reducer 4 <- Map 14 (SIMPLE_EDGE), Reducer 3 (SIMPLE_EDGE)
+        Reducer 5 <- Reducer 4 (SIMPLE_EDGE)
+        Reducer 6 <- Reducer 5 (SIMPLE_EDGE)
+        Reducer 9 <- Map 11 (SIMPLE_EDGE), Map 8 (SIMPLE_EDGE)
+#### A masked pattern was here ####
+      Vertices:
+        Map 1 
+            Map Operator Tree:
+                TableScan
+                  alias: customer
+                  filterExpr: ((c_birth_month) IN (9, 5) and c_current_addr_sk is not null) (type: boolean)
+                  Statistics: Num rows: 80000000 Data size: 1257604572 Basic stats: COMPLETE Column stats: COMPLETE
+                  Filter Operator
+                    predicate: ((c_birth_month) IN (9, 5) and c_current_addr_sk is not null) (type: boolean)
+                    Statistics: Num rows: 12307692 Data size: 193477628 Basic stats: COMPLETE Column stats: COMPLETE
+                    Select Operator
+                      expressions: c_customer_sk (type: int), c_current_addr_sk (type: int), CAST( c_birth_year AS decimal(12,2)) (type: decimal(12,2))
+                      outputColumnNames: _col0, _col1, _col2
+                      Statistics: Num rows: 12307692 Data size: 1428699984 Basic stats: COMPLETE Column stats: COMPLETE
+                      Reduce Output Operator
+                        key expressions: _col1 (type: int)
+                        null sort order: z
+                        sort order: +
+                        Map-reduce partition columns: _col1 (type: int)
+                        Statistics: Num rows: 12307692 Data size: 1428699984 Basic stats: COMPLETE Column stats: COMPLETE
+                        value expressions: _col0 (type: int), _col2 (type: decimal(12,2))
+            Execution mode: vectorized
+        Map 11 
+            Map Operator Tree:
+                TableScan
+                  alias: date_dim
+                  filterExpr: (d_year = 2001) (type: boolean)
+                  Statistics: Num rows: 73049 Data size: 584392 Basic stats: COMPLETE Column stats: COMPLETE
+                  Filter Operator
+                    predicate: (d_year = 2001) (type: boolean)
+                    Statistics: Num rows: 652 Data size: 5216 Basic stats: COMPLETE Column stats: COMPLETE
+                    Select Operator
+                      expressions: d_date_sk (type: int)
+                      outputColumnNames: _col0
+                      Statistics: Num rows: 652 Data size: 2608 Basic stats: COMPLETE Column stats: COMPLETE
+                      Reduce Output Operator
+                        key expressions: _col0 (type: int)
+                        null sort order: z
+                        sort order: +
+                        Map-reduce partition columns: _col0 (type: int)
+                        Statistics: Num rows: 652 Data size: 2608 Basic stats: COMPLETE Column stats: COMPLETE
+                      Select Operator
+                        expressions: _col0 (type: int)
+                        outputColumnNames: _col0
+                        Statistics: Num rows: 652 Data size: 2608 Basic stats: COMPLETE Column stats: COMPLETE
+                        Group By Operator
+                          aggregations: min(_col0), max(_col0), bloom_filter(_col0, expectedEntries=1000000)
+                          minReductionHashAggr: 0.99
+                          mode: hash
+                          outputColumnNames: _col0, _col1, _col2
+                          Statistics: Num rows: 1 Data size: 12 Basic stats: COMPLETE Column stats: COMPLETE
+                          Reduce Output Operator
+                            null sort order: 
+                            sort order: 
+                            Statistics: Num rows: 1 Data size: 12 Basic stats: COMPLETE Column stats: COMPLETE
+                            value expressions: _col0 (type: int), _col1 (type: int), _col2 (type: binary)
+            Execution mode: vectorized
+        Map 13 
+            Map Operator Tree:
+                TableScan
+                  alias: cd1
+                  filterExpr: ((cd_education_status = 'College') and (cd_gender = 'M')) (type: boolean)
+                  Statistics: Num rows: 1861800 Data size: 348156600 Basic stats: COMPLETE Column stats: COMPLETE
+                  Filter Operator
+                    predicate: ((cd_education_status = 'College') and (cd_gender = 'M')) (type: boolean)
+                    Statistics: Num rows: 103434 Data size: 19342158 Basic stats: COMPLETE Column stats: COMPLETE
+                    Select Operator
+                      expressions: cd_demo_sk (type: int), CAST( cd_dep_count AS decimal(12,2)) (type: decimal(12,2))
+                      outputColumnNames: _col0, _col1
+                      Statistics: Num rows: 103434 Data size: 11998344 Basic stats: COMPLETE Column stats: COMPLETE
+                      Reduce Output Operator
+                        key expressions: _col0 (type: int)
+                        null sort order: z
+                        sort order: +
+                        Map-reduce partition columns: _col0 (type: int)
+                        Statistics: Num rows: 103434 Data size: 11998344 Basic stats: COMPLETE Column stats: COMPLETE
+                        value expressions: _col1 (type: decimal(12,2))
+            Execution mode: vectorized
+        Map 14 
+            Map Operator Tree:
+                TableScan
+                  alias: item
+                  Statistics: Num rows: 462000 Data size: 48048000 Basic stats: COMPLETE Column stats: COMPLETE
+                  Select Operator
+                    expressions: i_item_sk (type: int), i_item_id (type: string)
+                    outputColumnNames: _col0, _col1
+                    Statistics: Num rows: 462000 Data size: 48048000 Basic stats: COMPLETE Column stats: COMPLETE
+                    Reduce Output Operator
+                      key expressions: _col0 (type: int)
+                      null sort order: z
+                      sort order: +
+                      Map-reduce partition columns: _col0 (type: int)
+                      Statistics: Num rows: 462000 Data size: 48048000 Basic stats: COMPLETE Column stats: COMPLETE
+                      value expressions: _col1 (type: string)
+            Execution mode: vectorized
+        Map 7 
+            Map Operator Tree:
+                TableScan
+                  alias: customer_address
+                  filterExpr: (ca_state) IN ('AL', 'MS', 'TN') (type: boolean)
+                  Statistics: Num rows: 40000000 Data size: 7480000000 Basic stats: COMPLETE Column stats: COMPLETE
+                  Filter Operator
+                    predicate: (ca_state) IN ('AL', 'MS', 'TN') (type: boolean)
+                    Statistics: Num rows: 2352941 Data size: 439999967 Basic stats: COMPLETE Column stats: COMPLETE
+                    Select Operator
+                      expressions: ca_address_sk (type: int), ca_state (type: string), ca_country (type: string)
+                      outputColumnNames: _col0, _col1, _col2
+                      Statistics: Num rows: 2352941 Data size: 439999967 Basic stats: COMPLETE Column stats: COMPLETE
+                      Reduce Output Operator
+                        key expressions: _col0 (type: int)
+                        null sort order: z
+                        sort order: +
+                        Map-reduce partition columns: _col0 (type: int)
+                        Statistics: Num rows: 2352941 Data size: 439999967 Basic stats: COMPLETE Column stats: COMPLETE
+                        value expressions: _col1 (type: string), _col2 (type: string)
+            Execution mode: vectorized
+        Map 8 
+            Map Operator Tree:
+                TableScan
+                  alias: catalog_sales
+                  filterExpr: (cs_sold_date_sk is not null and cs_bill_cdemo_sk is not null and cs_bill_customer_sk is not null and cs_sold_date_sk BETWEEN DynamicValue(RS_16_date_dim_d_date_sk_min) AND DynamicValue(RS_16_date_dim_d_date_sk_max) and in_bloom_filter(cs_sold_date_sk, DynamicValue(RS_16_date_dim_d_date_sk_bloom_filter))) (type: boolean)
+                  Statistics: Num rows: 287989836 Data size: 5736761432 Basic stats: COMPLETE Column stats: COMPLETE
+                  Filter Operator
+                    predicate: (cs_sold_date_sk is not null and cs_bill_cdemo_sk is not null and cs_bill_customer_sk is not null and cs_sold_date_sk BETWEEN DynamicValue(RS_16_date_dim_d_date_sk_min) AND DynamicValue(RS_16_date_dim_d_date_sk_max) and in_bloom_filter(cs_sold_date_sk, DynamicValue(RS_16_date_dim_d_date_sk_bloom_filter))) (type: boolean)
+                    Statistics: Num rows: 283692098 Data size: 5651150432 Basic stats: COMPLETE Column stats: COMPLETE
+                    Select Operator
+                      expressions: cs_sold_date_sk (type: int), cs_bill_customer_sk (type: int), cs_bill_cdemo_sk (type: int), cs_item_sk (type: int), CAST( cs_quantity AS decimal(12,2)) (type: decimal(12,2))
+                      outputColumnNames: _col0, _col1, _col2, _col3, _col4
+                      Statistics: Num rows: 283692098 Data size: 36136747832 Basic stats: COMPLETE Column stats: COMPLETE
+                      Reduce Output Operator
+                        key expressions: _col0 (type: int)
+                        null sort order: z
+                        sort order: +
+                        Map-reduce partition columns: _col0 (type: int)
+                        Statistics: Num rows: 283692098 Data size: 36136747832 Basic stats: COMPLETE Column stats: COMPLETE
+                        value expressions: _col1 (type: int), _col2 (type: int), _col3 (type: int), _col4 (type: decimal(12,2))
+            Execution mode: vectorized
+        Reducer 10 
+            Reduce Operator Tree:
+              Merge Join Operator
+                condition map:
+                     Inner Join 0 to 1
+                keys:
+                  0 _col2 (type: int)
+                  1 _col0 (type: int)
+                outputColumnNames: _col1, _col3, _col4, _col7
+                Statistics: Num rows: 15983636 Data size: 3543711716 Basic stats: COMPLETE Column stats: COMPLETE
+                Reduce Output Operator
+                  key expressions: _col1 (type: int)
+                  null sort order: z
+                  sort order: +
+                  Map-reduce partition columns: _col1 (type: int)
+                  Statistics: Num rows: 15983636 Data size: 3543711716 Basic stats: COMPLETE Column stats: COMPLETE
+                  value expressions: _col3 (type: int), _col4 (type: decimal(12,2)), _col7 (type: decimal(12,2))
+        Reducer 12 
+            Execution mode: vectorized
+            Reduce Operator Tree:
+              Group By Operator
+                aggregations: min(VALUE._col0), max(VALUE._col1), bloom_filter(VALUE._col2, expectedEntries=1000000)
+                mode: final
+                outputColumnNames: _col0, _col1, _col2
+                Statistics: Num rows: 1 Data size: 12 Basic stats: COMPLETE Column stats: COMPLETE
+                Reduce Output Operator
+                  null sort order: 
+                  sort order: 
+                  Statistics: Num rows: 1 Data size: 12 Basic stats: COMPLETE Column stats: COMPLETE
+                  value expressions: _col0 (type: int), _col1 (type: int), _col2 (type: binary)
+        Reducer 2 
+            Reduce Operator Tree:
+              Merge Join Operator
+                condition map:
+                     Inner Join 0 to 1
+                keys:
+                  0 _col1 (type: int)
+                  1 _col0 (type: int)
+                outputColumnNames: _col0, _col2, _col4, _col5
+                Statistics: Num rows: 723982 Data size: 168247562 Basic stats: COMPLETE Column stats: COMPLETE
+                Reduce Output Operator
+                  key expressions: _col0 (type: int)
+                  null sort order: z
+                  sort order: +
+                  Map-reduce partition columns: _col0 (type: int)
+                  Statistics: Num rows: 723982 Data size: 168247562 Basic stats: COMPLETE Column stats: COMPLETE
+                  value expressions: _col2 (type: decimal(12,2)), _col4 (type: string), _col5 (type: string)
+        Reducer 3 
+            Reduce Operator Tree:
+              Merge Join Operator
+                condition map:
+                     Inner Join 0 to 1
+                keys:
+                  0 _col0 (type: int)
+                  1 _col1 (type: int)
+                outputColumnNames: _col2, _col4, _col5, _col9, _col10, _col13
+                Statistics: Num rows: 940214 Data size: 338205010 Basic stats: COMPLETE Column stats: COMPLETE
+                Reduce Output Operator
+                  key expressions: _col9 (type: int)
+                  null sort order: z
+                  sort order: +
+                  Map-reduce partition columns: _col9 (type: int)
+                  Statistics: Num rows: 940214 Data size: 338205010 Basic stats: COMPLETE Column stats: COMPLETE
+                  value expressions: _col2 (type: decimal(12,2)), _col4 (type: string), _col5 (type: string), _col10 (type: decimal(12,2)), _col13 (type: decimal(12,2))
+        Reducer 4 
+            Reduce Operator Tree:
+              Merge Join Operator
+                condition map:
+                     Inner Join 0 to 1
+                keys:
+                  0 _col9 (type: int)
+                  1 _col0 (type: int)
+                outputColumnNames: _col2, _col4, _col5, _col10, _col13, _col15
+                Statistics: Num rows: 940214 Data size: 428465554 Basic stats: COMPLETE Column stats: COMPLETE
+                Group By Operator
+                  aggregations: sum(_col10), count(_col10), sum(_col2), count(_col2), sum(_col13), count(_col13)
+                  keys: _col15 (type: string), _col4 (type: string), _col5 (type: string), 0L (type: bigint)
+                  grouping sets: 0, 2, 3, 7
+                  minReductionHashAggr: 0.6694646
+                  mode: hash
+                  outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col9
+                  Statistics: Num rows: 3760856 Data size: 2448317256 Basic stats: COMPLETE Column stats: COMPLETE
+                  Reduce Output Operator
+                    key expressions: _col0 (type: string), _col1 (type: string), _col2 (type: string), _col3 (type: bigint)
+                    null sort order: zzzz
+                    sort order: ++++
+                    Map-reduce partition columns: _col0 (type: string), _col1 (type: string), _col2 (type: string), _col3 (type: bigint)
+                    Statistics: Num rows: 3760856 Data size: 2448317256 Basic stats: COMPLETE Column stats: COMPLETE
+                    value expressions: _col4 (type: decimal(22,2)), _col5 (type: bigint), _col6 (type: decimal(22,2)), _col7 (type: bigint), _col8 (type: decimal(22,2)), _col9 (type: bigint)
+        Reducer 5 
+            Execution mode: vectorized
+            Reduce Operator Tree:
+              Group By Operator
+                aggregations: sum(VALUE._col0), count(VALUE._col1), sum(VALUE._col2), count(VALUE._col3), sum(VALUE._col4), count(VALUE._col5)
+                keys: KEY._col0 (type: string), KEY._col1 (type: string), KEY._col2 (type: string), KEY._col3 (type: bigint)
+                mode: mergepartial
+                outputColumnNames: _col0, _col1, _col2, _col4, _col5, _col6, _col7, _col8, _col9
+                Statistics: Num rows: 1243096 Data size: 809255496 Basic stats: COMPLETE Column stats: COMPLETE
+                pruneGroupingSetId: true
+                Top N Key Operator
+                  sort order: +++
+                  keys: _col2 (type: string), _col1 (type: string), _col0 (type: string)
+                  null sort order: zza
+                  Statistics: Num rows: 1243096 Data size: 809255496 Basic stats: COMPLETE Column stats: COMPLETE
+                  top n: 100
+                  Select Operator
+                    expressions: _col2 (type: string), _col1 (type: string), _col0 (type: string), CAST( (_col4 / _col5) AS decimal(16,6)) (type: decimal(16,6)), CAST( (_col6 / _col7) AS decimal(16,6)) (type: decimal(16,6)), CAST( (_col8 / _col9) AS decimal(16,6)) (type: decimal(16,6))
+                    outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5
+                    Statistics: Num rows: 1243096 Data size: 769476424 Basic stats: COMPLETE Column stats: COMPLETE
+                    Reduce Output Operator
+                      key expressions: _col0 (type: string), _col1 (type: string), _col2 (type: string)
+                      null sort order: zza
+                      sort order: +++
+                      Statistics: Num rows: 1243096 Data size: 769476424 Basic stats: COMPLETE Column stats: COMPLETE
+                      value expressions: _col3 (type: decimal(16,6)), _col4 (type: decimal(16,6)), _col5 (type: decimal(16,6))
+        Reducer 6 
+            Execution mode: vectorized
+            Reduce Operator Tree:
+              Select Operator
+                expressions: KEY.reducesinkkey0 (type: string), KEY.reducesinkkey1 (type: string), KEY.reducesinkkey2 (type: string), VALUE._col0 (type: decimal(16,6)), VALUE._col1 (type: decimal(16,6)), VALUE._col2 (type: decimal(16,6))
+                outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5
+                Statistics: Num rows: 1243096 Data size: 769476424 Basic stats: COMPLETE Column stats: COMPLETE
+                Limit
+                  Number of rows: 100
+                  Statistics: Num rows: 100 Data size: 61900 Basic stats: COMPLETE Column stats: COMPLETE
+                  File Output Operator
+                    compressed: false
+                    Statistics: Num rows: 100 Data size: 61900 Basic stats: COMPLETE Column stats: COMPLETE
+                    table:
+                        input format: org.apache.hadoop.mapred.SequenceFileInputFormat
+                        output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
+                        serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
+        Reducer 9 
+            Reduce Operator Tree:
+              Merge Join Operator
+                condition map:
+                     Inner Join 0 to 1
+                keys:
+                  0 _col0 (type: int)
+                  1 _col0 (type: int)
+                outputColumnNames: _col1, _col2, _col3, _col4
+                Statistics: Num rows: 100578970 Data size: 12301626036 Basic stats: COMPLETE Column stats: COMPLETE
+                Reduce Output Operator
+                  key expressions: _col2 (type: int)
+                  null sort order: z
+                  sort order: +
+                  Map-reduce partition columns: _col2 (type: int)
+                  Statistics: Num rows: 100578970 Data size: 12301626036 Basic stats: COMPLETE Column stats: COMPLETE
+                  value expressions: _col1 (type: int), _col3 (type: int), _col4 (type: decimal(12,2))
+
+  Stage: Stage-0
+    Fetch Operator
+      limit: 100
+      Processor Tree:
+        ListSink
+