diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java index 0e7e82b..09d77d4 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -2299,6 +2299,7 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer { // We allow stateful functions in the SELECT list (but nowhere else) tcCtx.setAllowStatefulFunctions(true); ExprNodeDesc exp = genExprNodeDesc(expr, inputRR, tcCtx); + colAlias = extractName(exp, colAlias); col_list.add(exp); if (!StringUtils.isEmpty(alias) && (out_rwsch.get(null, colAlias) != null)) { @@ -2346,6 +2347,26 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer { return output; } + private String extractName(ExprNodeDesc exp, String colAlias) { + if (!colAlias.startsWith(autogenColAliasPrfxLbl)) { + return colAlias; + } + ExprNodeColumnDesc column = null; + if (exp instanceof ExprNodeColumnDesc) { + column = (ExprNodeColumnDesc) exp; + } + if (exp instanceof ExprNodeGenericFuncDesc) { + List children = ((ExprNodeGenericFuncDesc)exp).getChildren(); + if (children.size() == 1 && children.get(0) instanceof ExprNodeColumnDesc) { + column = (ExprNodeColumnDesc) children.get(0); + } + } + if (column != null && !column.getColumn().startsWith(autogenColAliasPrfxLbl)) { + return column.getColumn(); + } + return colAlias; + } + /** * Class to store GenericUDAF related information. */