diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java index 5ff74f2..71d34eb 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -3046,7 +3046,7 @@ public Object post(Object t) { ParseDriver.adaptor.addChild(child1, ParseDriver.adaptor.create( HiveParser.Identifier, VirtualColumn.GROUPINGID.getName())); ASTNode child2 = (ASTNode) ParseDriver.adaptor.create(HiveParser.IntegralLiteral, - String.valueOf(IntMath.mod(-i, grpByAstExprs.size()))); + String.valueOf(IntMath.mod(-i-1, grpByAstExprs.size()))); root.setChild(1, child1); root.addChild(child2); found.setValue(true); diff --git ql/src/test/results/clientpositive/groupby_grouping_sets_grouping.q.out ql/src/test/results/clientpositive/groupby_grouping_sets_grouping.q.out index dcc80f7..62f40cd 100644 --- ql/src/test/results/clientpositive/groupby_grouping_sets_grouping.q.out +++ ql/src/test/results/clientpositive/groupby_grouping_sets_grouping.q.out @@ -56,7 +56,7 @@ STAGE PLANS: outputColumnNames: _col0, _col1, _col2 Statistics: Num rows: 4 Data size: 40 Basic stats: COMPLETE Column stats: NONE Select Operator - expressions: _col0 (type: int), _col1 (type: int), _col2 (type: int), grouping(_col2, 0) (type: tinyint), grouping(_col2, 1) (type: tinyint) + expressions: _col0 (type: int), _col1 (type: int), _col2 (type: int), grouping(_col2, 1) (type: tinyint), grouping(_col2, 0) (type: tinyint) outputColumnNames: _col0, _col1, _col2, _col3, _col4 Statistics: Num rows: 4 Data size: 40 Basic stats: COMPLETE Column stats: NONE File Output Operator @@ -86,15 +86,15 @@ POSTHOOK: type: QUERY POSTHOOK: Input: default@t1 #### A masked pattern was here #### NULL NULL 0 0 0 -1 NULL 1 1 0 +1 NULL 1 0 1 1 NULL 3 1 1 1 1 3 1 1 -2 NULL 1 1 0 +2 NULL 1 0 1 2 2 3 1 1 -3 NULL 1 1 0 +3 NULL 1 0 1 3 NULL 3 1 1 3 3 3 1 1 -4 NULL 1 1 0 +4 NULL 1 0 1 4 5 3 1 1 PREHOOK: query: explain select key, value, `grouping__id`, grouping(key), grouping(value) @@ -138,7 +138,7 @@ STAGE PLANS: outputColumnNames: _col0, _col1, _col2 Statistics: Num rows: 6 Data size: 60 Basic stats: COMPLETE Column stats: NONE Select Operator - expressions: _col0 (type: int), _col1 (type: int), _col2 (type: int), grouping(_col2, 0) (type: tinyint), grouping(_col2, 1) (type: tinyint) + expressions: _col0 (type: int), _col1 (type: int), _col2 (type: int), grouping(_col2, 1) (type: tinyint), grouping(_col2, 0) (type: tinyint) outputColumnNames: _col0, _col1, _col2, _col3, _col4 Statistics: Num rows: 6 Data size: 60 Basic stats: COMPLETE Column stats: NONE File Output Operator @@ -168,20 +168,20 @@ POSTHOOK: type: QUERY POSTHOOK: Input: default@t1 #### A masked pattern was here #### NULL NULL 0 0 0 -NULL NULL 2 0 1 -NULL 1 2 0 1 -NULL 2 2 0 1 -NULL 3 2 0 1 -NULL 5 2 0 1 -1 NULL 1 1 0 +NULL NULL 2 1 0 +NULL 1 2 1 0 +NULL 2 2 1 0 +NULL 3 2 1 0 +NULL 5 2 1 0 +1 NULL 1 0 1 1 NULL 3 1 1 1 1 3 1 1 -2 NULL 1 1 0 +2 NULL 1 0 1 2 2 3 1 1 -3 NULL 1 1 0 +3 NULL 1 0 1 3 NULL 3 1 1 3 3 3 1 1 -4 NULL 1 1 0 +4 NULL 1 0 1 4 5 3 1 1 PREHOOK: query: explain select key, value @@ -227,7 +227,7 @@ STAGE PLANS: outputColumnNames: _col0, _col1, _col2 Statistics: Num rows: 6 Data size: 60 Basic stats: COMPLETE Column stats: NONE Filter Operator - predicate: (UDFToInteger(grouping(_col2, 0)) = 1) (type: boolean) + predicate: (UDFToInteger(grouping(_col2, 1)) = 1) (type: boolean) Statistics: Num rows: 3 Data size: 30 Basic stats: COMPLETE Column stats: NONE Select Operator expressions: _col0 (type: int), _col1 (type: int) @@ -261,15 +261,16 @@ having grouping(key) = 1 POSTHOOK: type: QUERY POSTHOOK: Input: default@t1 #### A masked pattern was here #### -1 NULL +NULL NULL +NULL 1 +NULL 2 +NULL 3 +NULL 5 1 NULL 1 1 -2 NULL 2 2 3 NULL -3 NULL 3 3 -4 NULL 4 5 PREHOOK: query: explain select key, value, grouping(key)+grouping(value) as x @@ -318,10 +319,10 @@ STAGE PLANS: outputColumnNames: _col0, _col1, _col2 Statistics: Num rows: 6 Data size: 60 Basic stats: COMPLETE Column stats: NONE Filter Operator - predicate: ((UDFToInteger(grouping(_col2, 0)) = 1) or (UDFToInteger(grouping(_col2, 1)) = 1)) (type: boolean) + predicate: ((UDFToInteger(grouping(_col2, 1)) = 1) or (UDFToInteger(grouping(_col2, 0)) = 1)) (type: boolean) Statistics: Num rows: 6 Data size: 60 Basic stats: COMPLETE Column stats: NONE Select Operator - expressions: _col0 (type: int), _col1 (type: int), (grouping(_col2, 0) + grouping(_col2, 1)) (type: tinyint) + expressions: _col0 (type: int), _col1 (type: int), (grouping(_col2, 1) + grouping(_col2, 0)) (type: tinyint) outputColumnNames: _col0, _col1, _col2 Statistics: Num rows: 6 Data size: 60 Basic stats: COMPLETE Column stats: NONE File Output Operator @@ -432,7 +433,7 @@ STAGE PLANS: outputColumnNames: _col0, _col1, _col2 Statistics: Num rows: 4 Data size: 40 Basic stats: COMPLETE Column stats: NONE Select Operator - expressions: _col0 (type: int), _col1 (type: int), _col2 (type: int), grouping(_col2, 0) (type: tinyint), grouping(_col2, 1) (type: tinyint) + expressions: _col0 (type: int), _col1 (type: int), _col2 (type: int), grouping(_col2, 1) (type: tinyint), grouping(_col2, 0) (type: tinyint) outputColumnNames: _col0, _col1, _col2, _col3, _col4 Statistics: Num rows: 4 Data size: 40 Basic stats: COMPLETE Column stats: NONE File Output Operator @@ -462,15 +463,15 @@ POSTHOOK: type: QUERY POSTHOOK: Input: default@t1 #### A masked pattern was here #### NULL NULL 0 0 0 -1 NULL 1 1 0 +1 NULL 1 0 1 1 NULL 3 1 1 1 1 3 1 1 -2 NULL 1 1 0 +2 NULL 1 0 1 2 2 3 1 1 -3 NULL 1 1 0 +3 NULL 1 0 1 3 NULL 3 1 1 3 3 3 1 1 -4 NULL 1 1 0 +4 NULL 1 0 1 4 5 3 1 1 PREHOOK: query: explain select key, value, `grouping__id`, grouping(key), grouping(value) @@ -514,7 +515,7 @@ STAGE PLANS: outputColumnNames: _col0, _col1, _col2 Statistics: Num rows: 6 Data size: 60 Basic stats: COMPLETE Column stats: NONE Select Operator - expressions: _col0 (type: int), _col1 (type: int), _col2 (type: int), grouping(_col2, 0) (type: tinyint), grouping(_col2, 1) (type: tinyint) + expressions: _col0 (type: int), _col1 (type: int), _col2 (type: int), grouping(_col2, 1) (type: tinyint), grouping(_col2, 0) (type: tinyint) outputColumnNames: _col0, _col1, _col2, _col3, _col4 Statistics: Num rows: 6 Data size: 60 Basic stats: COMPLETE Column stats: NONE File Output Operator @@ -544,20 +545,20 @@ POSTHOOK: type: QUERY POSTHOOK: Input: default@t1 #### A masked pattern was here #### NULL NULL 0 0 0 -NULL NULL 2 0 1 -NULL 1 2 0 1 -NULL 2 2 0 1 -NULL 3 2 0 1 -NULL 5 2 0 1 -1 NULL 1 1 0 +NULL NULL 2 1 0 +NULL 1 2 1 0 +NULL 2 2 1 0 +NULL 3 2 1 0 +NULL 5 2 1 0 +1 NULL 1 0 1 1 NULL 3 1 1 1 1 3 1 1 -2 NULL 1 1 0 +2 NULL 1 0 1 2 2 3 1 1 -3 NULL 1 1 0 +3 NULL 1 0 1 3 NULL 3 1 1 3 3 3 1 1 -4 NULL 1 1 0 +4 NULL 1 0 1 4 5 3 1 1 PREHOOK: query: explain select key, value @@ -592,7 +593,7 @@ STAGE PLANS: outputColumnNames: _col0, _col1, _col2 Statistics: Num rows: 12 Data size: 120 Basic stats: COMPLETE Column stats: NONE Filter Operator - predicate: (grouping(_col2, 0) = 1) (type: boolean) + predicate: (grouping(_col2, 1) = 1) (type: boolean) Statistics: Num rows: 6 Data size: 60 Basic stats: COMPLETE Column stats: NONE Reduce Output Operator key expressions: _col0 (type: int), _col1 (type: int), _col2 (type: int) @@ -634,15 +635,16 @@ having grouping(key) = 1 POSTHOOK: type: QUERY POSTHOOK: Input: default@t1 #### A masked pattern was here #### -1 NULL +NULL NULL +NULL 1 +NULL 2 +NULL 3 +NULL 5 1 NULL 1 1 -2 NULL 2 2 3 NULL -3 NULL 3 3 -4 NULL 4 5 PREHOOK: query: explain select key, value, grouping(key)+grouping(value) as x @@ -680,7 +682,7 @@ STAGE PLANS: outputColumnNames: _col0, _col1, _col2 Statistics: Num rows: 12 Data size: 120 Basic stats: COMPLETE Column stats: NONE Filter Operator - predicate: ((grouping(_col2, 0) = 1) or (grouping(_col2, 1) = 1)) (type: boolean) + predicate: ((grouping(_col2, 1) = 1) or (grouping(_col2, 0) = 1)) (type: boolean) Statistics: Num rows: 12 Data size: 120 Basic stats: COMPLETE Column stats: NONE Reduce Output Operator key expressions: _col0 (type: int), _col1 (type: int), _col2 (type: int) @@ -694,7 +696,7 @@ STAGE PLANS: outputColumnNames: _col0, _col1, _col2 Statistics: Num rows: 6 Data size: 60 Basic stats: COMPLETE Column stats: NONE Select Operator - expressions: _col0 (type: int), _col1 (type: int), (grouping(_col2, 0) + grouping(_col2, 1)) (type: tinyint) + expressions: _col0 (type: int), _col1 (type: int), (grouping(_col2, 1) + grouping(_col2, 0)) (type: tinyint) outputColumnNames: _col0, _col1, _col2 Statistics: Num rows: 6 Data size: 60 Basic stats: COMPLETE Column stats: NONE File Output Operator