You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2019/09/25 23:40:51 UTC

[GitHub] [hive] jcamachor commented on a change in pull request #783: HIVE-22232

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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org