[ https://issues.apache.org/jira/browse/HIVE-24478?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17273989#comment-17273989 ]
Panagiotis Garefalakis commented on HIVE-24478: ----------------------------------------------- The issue is actually originates in the SemanticAnalyzer -- where Having clause should update both aggregationExpressions and also check for Distinct expressions. There can be cases where the aggregration is on a distinct column as in the example above. > Subquery GroupBy with Distinct SemanticException: Invalid column reference > -------------------------------------------------------------------------- > > Key: HIVE-24478 > URL: https://issues.apache.org/jira/browse/HIVE-24478 > Project: Hive > Issue Type: Bug > Reporter: Panagiotis Garefalakis > Priority: Major > Labels: pull-request-available > Time Spent: 10m > Remaining Estimate: 0h > > {code:java} > CREATE TABLE tmp_src1( > `npp` string, > `nsoc` string) stored as orc; > INSERT INTO tmp_src1 (npp,nsoc) VALUES ('1-1000CG61', '7273111'); > SELECT `min_nsoc` > FROM > (SELECT `npp`, > MIN(`nsoc`) AS `min_nsoc`, > COUNT(DISTINCT `nsoc`) AS `nb_nsoc` > FROM tmp_src1 > GROUP BY `npp`) `a` > WHERE `nb_nsoc` > 0; > {code} > Issue: > {code:java} > org.apache.hadoop.hive.ql.parse.SemanticException: Line 0:-1 Invalid column > reference 'nsoc' at > org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.genGroupByPlanGroupByOperator1(SemanticAnalyzer.java:5405) > {code} > Query runs fine when we include `nb_nsoc` in the Select expression -- This message was sent by Atlassian Jira (v8.3.4#803005)