jcamachor commented on a change in pull request #783: HIVE-22232
URL: https://github.com/apache/hive/pull/783#discussion_r328383460
 
 

 ##########
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/ASTConverter.java
 ##########
 @@ -160,17 +160,27 @@ private ASTNode convert() throws 
CalciteSemanticException {
       }
 
       HiveAggregate hiveAgg = (HiveAggregate) groupBy;
-      for (int pos : hiveAgg.getAggregateColumnsOrder()) {
-        RexInputRef iRef = new RexInputRef(groupBy.getGroupSet().nth(pos),
-            
groupBy.getCluster().getTypeFactory().createSqlType(SqlTypeName.ANY));
-        b.add(iRef.accept(new RexVisitor(schema, false, 
root.getCluster().getRexBuilder())));
-      }
-      for (int pos = 0; pos < groupBy.getGroupCount(); pos++) {
-        if (!hiveAgg.getAggregateColumnsOrder().contains(pos)) {
+      if (hiveAgg.getAggregateColumnsOrder() != null) {
+        // Aggregation columns may have been sorted in specific order
+        for (int pos : hiveAgg.getAggregateColumnsOrder()) {
           RexInputRef iRef = new RexInputRef(groupBy.getGroupSet().nth(pos),
               
groupBy.getCluster().getTypeFactory().createSqlType(SqlTypeName.ANY));
           b.add(iRef.accept(new RexVisitor(schema, false, 
root.getCluster().getRexBuilder())));
         }
+        for (int pos = 0; pos < groupBy.getGroupCount(); pos++) {
+          if (!hiveAgg.getAggregateColumnsOrder().contains(pos)) {
 
 Review comment:
   That will remove the duplicate code at the cost of checking if condition 
within the loop. Instead, I will create an aux method with the following code:
   ```
             RexInputRef iRef = new RexInputRef(i,
                 
groupBy.getCluster().getTypeFactory().createSqlType(SqlTypeName.ANY));
             b.add(iRef.accept(new RexVisitor(schema, false, 
root.getCluster().getRexBuilder())));
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to