hive-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Work logged] (HIVE-16924) Support distinct in presence of Group By
Date Mon, 25 Feb 2019 13:36:00 GMT

     [ https://issues.apache.org/jira/browse/HIVE-16924?focusedWorklogId=203661&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-203661
]

ASF GitHub Bot logged work on HIVE-16924:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 25/Feb/19 13:35
            Start Date: 25/Feb/19 13:35
    Worklog Time Spent: 10m 
      Work Description: miklosgergely commented on pull request #544: HIVE-16924 Support distinct
in presence of Group By
URL: https://github.com/apache/hive/pull/544#discussion_r259824341
 
 

 ##########
 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:
   agree, removed
 
----------------------------------------------------------------
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:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 203661)
    Time Spent: 1h 40m  (was: 1.5h)

> Support distinct in presence of Group By 
> -----------------------------------------
>
>                 Key: HIVE-16924
>                 URL: https://issues.apache.org/jira/browse/HIVE-16924
>             Project: Hive
>          Issue Type: New Feature
>          Components: Query Planning
>            Reporter: Carter Shanklin
>            Assignee: Miklos Gergely
>            Priority: Major
>              Labels: pull-request-available
>         Attachments: HIVE-16924.01.patch, HIVE-16924.02.patch, HIVE-16924.03.patch, HIVE-16924.04.patch,
HIVE-16924.05.patch, HIVE-16924.06.patch, HIVE-16924.07.patch, HIVE-16924.08.patch
>
>          Time Spent: 1h 40m
>  Remaining Estimate: 0h
>
> {code:sql}
> create table e011_01 (c1 int, c2 smallint);
> insert into e011_01 values (1, 1), (2, 2);
> {code}
> These queries should work:
> {code:sql}
> select distinct c1, count(*) from e011_01 group by c1;
> select distinct c1, avg(c2) from e011_01 group by c1;
> {code}
> Currently, you get : 
> FAILED: SemanticException 1:52 SELECT DISTINCT and GROUP BY can not be in the same query.
Error encountered near token 'c1'



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message