kgyrtkirk commented on a change in pull request #544: HIVE-16924 Support 
distinct in presence of Group By
URL: https://github.com/apache/hive/pull/544#discussion_r259776469
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
 ##########
 @@ -4194,27 +4191,29 @@ public static long unsetBit(long bitmap, int bitIdx) {
   }
 
   /**
-   * This function is a wrapper of parseInfo.getGroupByForClause which
-   * automatically translates SELECT DISTINCT a,b,c to SELECT a,b,c GROUP BY
-   * a,b,c.
+   * Returns the GBY, if present;
+   * DISTINCT, if present, will be handled when generating the SELECT.
    */
   List<ASTNode> getGroupByForClause(QBParseInfo parseInfo, String dest) throws 
SemanticException {
-    if (parseInfo.getSelForClause(dest).getToken().getType() == 
HiveParser.TOK_SELECTDI) {
-      ASTNode selectExprs = parseInfo.getSelForClause(dest);
-      List<ASTNode> result = new ArrayList<ASTNode>(selectExprs == null ? 0
-          : selectExprs.getChildCount());
-      if (selectExprs != null) {
-        for (int i = 0; i < selectExprs.getChildCount(); ++i) {
-          if (((ASTNode) selectExprs.getChild(i)).getToken().getType() == 
HiveParser.QUERY_HINT) {
+    // When *not* invoked by CalcitePlanner, return the DISTINCT as a GBY
+    // CBO will handle the DISTINCT in 
CalcitePlannerAction.genSelectLogicalPlan
+    ASTNode selectExpr = parseInfo.getSelForClause(dest);
+    Collection<ASTNode> aggregateFunction = 
parseInfo.getDestToAggregationExprs().get(dest).values();
+    if (isSelectDistinct(selectExpr) && !isGroupBy(selectExpr) && 
!isAggregateInSelect(selectExpr, aggregateFunction)) {
+      List<ASTNode> result = new ArrayList<ASTNode>(selectExpr == null ? 0 : 
selectExpr.getChildCount());
+      if (selectExpr != null) {
 
 Review comment:
   please kill these null checks
   if it would be null we would already have run into an NPE in the earlier and 
in the new code

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


With regards,
Apache Git Services

Reply via email to