diff --git a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConstantPropagateProcCtx.java b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConstantPropagateProcCtx.java index 0a61f12..2ca801d 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConstantPropagateProcCtx.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConstantPropagateProcCtx.java @@ -82,7 +82,7 @@ public ConstantPropagateProcCtx(ConstantPropagateOption option) { * @throws SemanticException */ private ColumnInfo resolve(ColumnInfo ci, RowSchema rs, RowSchema parentRS) { - // Resolve new ColumnInfo from + // Resolve new ColumnInfo from String alias = ci.getAlias(); if (alias == null) { alias = ci.getInternalName(); @@ -152,7 +152,6 @@ private ColumnInfo resolve(ColumnInfo ci, RowSchema rs, RowSchema parentRS) { if (e.getValue().isSame(f.getValue())) { found = true; } - break; } } if (!found) { @@ -172,12 +171,24 @@ private ColumnInfo resolve(ColumnInfo ci, RowSchema rs, RowSchema parentRS) { Map c = opToConstantExprs.get(parent); for (Entry e : c.entrySet()) { ColumnInfo ci = e.getKey(); - ColumnInfo rci = null; ExprNodeDesc constant = e.getValue(); - rci = resolve(ci, rs, parent.getSchema()); - if (rci != null) { - constants.put(rci, constant); - } else { + boolean resolved = false; + + for (Entry entry : op.getColumnExprMap().entrySet()) { + if (entry.getValue().isSame(constant)) { + constants.put(rs.getColumnInfo(entry.getKey()), constant); + resolved = true; + } + } + + if (!resolved) { + ColumnInfo rci = resolve(ci, rs, parent.getSchema()); + if (rci != null) { + constants.put(rci, constant); + resolved = true; + } + } + if (!resolved) { LOG.debug("Can't resolve " + ci.getTabAlias() + "." + ci.getAlias() + "(" + ci.getInternalName() + ") from rs:" + rs); }