diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java index 19110ce..630c3e9 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -12225,7 +12225,7 @@ private boolean canHandleQuery(QB qbToChk, boolean topLevelQB) { private RelOptSchema relOptSchema; private SemanticException semanticException; private Map partitionCache; - private AtomicInteger noColsMissingStats = new AtomicInteger(0); + private final AtomicInteger noColsMissingStats = new AtomicInteger(0); List topLevelFieldSchema; // TODO: Do we need to keep track of RR, ColNameToPosMap for every op or @@ -13819,16 +13819,12 @@ private RelNode genSelectLogicalPlan(QB qb, RelNode srcRel) throws SemanticExcep } // 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); @@ -13856,7 +13852,6 @@ private RelNode genSelectLogicalPlan(QB qb, RelNode srcRel) throws SemanticExcep ErrorMsg.INVALID_AS.getMsg())); } - ASTNode expr; String tabAlias; String colAlias; @@ -13893,6 +13888,9 @@ private RelNode genSelectLogicalPlan(QB qb, RelNode srcRel) throws SemanticExcep 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);