You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ha...@apache.org on 2014/10/13 07:32:42 UTC

svn commit: r1631285 - /hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java

Author: hashutosh
Date: Mon Oct 13 05:32:41 2014
New Revision: 1631285

URL: http://svn.apache.org/r1631285
Log:
HIVE-8413 : [CBO] Handle ill-formed queries which have distinct, having in incorrect context  (Ashutosh Chauhan via Sergey Shelukhin)

Modified:
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java?rev=1631285&r1=1631284&r2=1631285&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java Mon Oct 13 05:32:41 2014
@@ -13833,16 +13833,12 @@ public class SemanticAnalyzer extends Ba
       }
 
       // 5. Bailout if select involves UDTF
-      ASTNode udtfExpr = (ASTNode) selExprList.getChild(posn).getChild(0);
-      GenericUDTF genericUDTF = null;
-      int udtfExprType = udtfExpr.getType();
-      if (udtfExprType == HiveParser.TOK_FUNCTION || udtfExprType == HiveParser.TOK_FUNCTIONSTAR) {
-        String funcName = TypeCheckProcFactory.DefaultExprProcessor.getFunctionText(udtfExpr, true);
+      ASTNode expr = (ASTNode) selExprList.getChild(posn).getChild(0);
+      int exprType = expr.getType();
+      if (exprType == HiveParser.TOK_FUNCTION || exprType == HiveParser.TOK_FUNCTIONSTAR) {
+        String funcName = TypeCheckProcFactory.DefaultExprProcessor.getFunctionText(expr, true);
         FunctionInfo fi = FunctionRegistry.getFunctionInfo(funcName);
-        if (fi != null) {
-          genericUDTF = fi.getGenericUDTF();
-        }
-        if (genericUDTF != null) {
+        if (fi != null && fi.getGenericUDTF() != null) {
           String msg = String.format("UDTF " + funcName + " is currently not supported in CBO,"
               + " turn off cbo to use UDTF " + funcName);
           LOG.debug(msg);
@@ -13870,7 +13866,6 @@ public class SemanticAnalyzer extends Ba
               ErrorMsg.INVALID_AS.getMsg()));
         }
 
-        ASTNode expr;
         String tabAlias;
         String colAlias;
 
@@ -13907,6 +13902,9 @@ public class SemanticAnalyzer extends Ba
           pos = genColListRegex(unescapeIdentifier(expr.getChild(1).getText()),
               unescapeIdentifier(expr.getChild(0).getChild(0).getText().toLowerCase()), expr,
               col_list, inputRR, pos, out_rwsch, tabAliasesForAllProjs, subQuery);
+        } else if (expr.toStringTree().contains("TOK_FUNCTIONDI") && !(srcRel instanceof HiveAggregateRel)) {
+          // Likely a malformed query eg, select hash(distinct c1) from t1;
+          throw new OptiqSemanticException("Distinct without an aggreggation.");
         } else {
           // Case when this is an expression
           TypeCheckCtx tcCtx = new TypeCheckCtx(inputRR);
@@ -14119,6 +14117,10 @@ public class SemanticAnalyzer extends Ba
       ASTNode havingClause = qbp.getHavingForClause(qbp.getClauseNames().iterator().next());
 
       if (havingClause != null) {
+        if (!(srcRel instanceof HiveAggregateRel)) {
+          // ill-formed query like select * from t1 having c1 > 0;
+          throw new OptiqSemanticException("Having clause without any group-by.");
+        }
         validateNoHavingReferenceToAlias(qb,  (ASTNode) havingClause.getChild(0));
         gbFilter = genFilterRelNode(qb, (ASTNode) havingClause.getChild(0), srcRel, aliasToRel,
             true);