diff --git a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConstantPropagateProcFactory.java b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConstantPropagateProcFactory.java index 11159d2..a140399 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConstantPropagateProcFactory.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConstantPropagateProcFactory.java @@ -19,7 +19,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; -import java.util.HashMap; +import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -28,7 +28,7 @@ import java.util.Set; import java.util.Stack; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.collections.CollectionUtils; import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.ql.exec.ColumnInfo; import org.apache.hadoop.hive.ql.exec.FileSinkOperator; @@ -106,7 +106,8 @@ * Factory for generating the different node processors used by ConstantPropagate. */ public final class ConstantPropagateProcFactory { - protected static final Logger LOG = LoggerFactory.getLogger(ConstantPropagateProcFactory.class.getName()); + protected static final Logger LOG = + LoggerFactory.getLogger(ConstantPropagateProcFactory.class.getName()); protected static Set> propagatableUdfs = new HashSet>(); static { @@ -130,9 +131,6 @@ public static ColumnInfo resolveColumn(RowSchema rs, if (ci == null) { ci = rs.getColumnInfo(desc.getColumn()); } - if (ci == null) { - return null; - } return ci; } @@ -182,9 +180,7 @@ private static ExprNodeConstantDesc typeCast(ExprNodeDesc desc, TypeInfo ti, boo if (unSupportedTypes.contains(priti.getPrimitiveCategory()) || unSupportedTypes.contains(descti.getPrimitiveCategory())) { // FIXME: support template types. It currently has conflict with ExprNodeConstantDesc - if (LOG.isDebugEnabled()) { - LOG.debug("Unsupported types " + priti + "; " + descti); - } + LOG.debug("Unsupported types {}; {}", priti, descti); return null; } @@ -195,17 +191,14 @@ private static ExprNodeConstantDesc typeCast(ExprNodeDesc desc, TypeInfo ti, boo priti.getPrimitiveCategory()) && !unsafeConversionTypes.contains( descti.getPrimitiveCategory()); if (performSafeTypeCast && brokenDataTypesCombination) { - if (LOG.isDebugEnabled()) { - LOG.debug("Unsupported cast " + priti + "; " + descti); - } + LOG.debug("Unsupported cast {}; {}", priti, descti); return null; } - if (LOG.isDebugEnabled()) { - LOG.debug("Casting " + desc + " to type " + ti); - } + LOG.debug("Casting {} to type {}", desc, ti); ExprNodeConstantDesc c = (ExprNodeConstantDesc) desc; - if (null != c.getFoldedFromVal() && priti.getTypeName().equals(serdeConstants.STRING_TYPE_NAME)) { + if (null != c.getFoldedFromVal() + && priti.getTypeName().equals(serdeConstants.STRING_TYPE_NAME)) { // avoid double casting to preserve original string representation of constant. return new ExprNodeConstantDesc(c.getFoldedFromVal()); } @@ -219,15 +212,15 @@ private static ExprNodeConstantDesc typeCast(ExprNodeDesc desc, TypeInfo ti, boo // Convert integer related types because converters are not sufficient if (convObj instanceof Integer) { switch (priti.getPrimitiveCategory()) { - case BYTE: - convObj = new Byte((byte) (((Integer) convObj).intValue())); - break; - case SHORT: - convObj = new Short((short) ((Integer) convObj).intValue()); - break; - case LONG: - convObj = new Long(((Integer) convObj).intValue()); - default: + case BYTE: + convObj = Byte.valueOf(((Integer) convObj).byteValue()); + break; + case SHORT: + convObj = Short.valueOf(((Integer) convObj).shortValue()); + break; + case LONG: + convObj = Long.valueOf(((Integer) convObj).longValue()); + default: } } return new ExprNodeConstantDesc(ti, convObj); @@ -284,7 +277,7 @@ private static ExprNodeDesc foldNegative(ExprNodeDesc desc) throws UDFArgumentEx childUDF instanceof GenericUDFOPNull || childUDF instanceof GenericUDFOPNotNull) { List newGrandChildren = new ArrayList(); - for(ExprNodeDesc grandChild : grandChildren) { + for (ExprNodeDesc grandChild : grandChildren) { newGrandChildren.add(foldNegative(grandChild)); } @@ -294,22 +287,22 @@ private static ExprNodeDesc foldNegative(ExprNodeDesc desc) throws UDFArgumentEx } else if (childUDF instanceof GenericUDFOPAnd || childUDF instanceof GenericUDFOPOr) { List newGrandChildren = new ArrayList(); - for(ExprNodeDesc grandChild : grandChildren) { + for (ExprNodeDesc grandChild : grandChildren) { newGrandChildren.add(foldNegative( ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPNot(), - Arrays.asList(grandChild)))); + Collections.singletonList(grandChild)))); } return ExprNodeGenericFuncDesc.newInstance( childUDF.negative(), newGrandChildren); - }else if (childUDF instanceof GenericUDFOPNot) { + } else if (childUDF instanceof GenericUDFOPNot) { return foldNegative(child.getChildren().get(0)); } else { // For operator like if() that cannot be handled, leave not() as it // is and continue processing the children List newGrandChildren = new ArrayList(); - for(ExprNodeDesc grandChild : grandChildren) { + for (ExprNodeDesc grandChild : grandChildren) { newGrandChildren.add(foldNegative(grandChild)); } childDesc.setChildren(newGrandChildren); @@ -355,9 +348,9 @@ private static ExprNodeDesc foldExprShortcut(ExprNodeDesc desc, Map " + shortcut); - } + LOG.debug("Folding expression: {} -> {}", desc, shortcut); return shortcut; } ((ExprNodeGenericFuncDesc) desc).setChildren(newExprs); @@ -414,26 +405,22 @@ private static ExprNodeDesc foldExprFull(ExprNodeDesc desc, Map " + constant); - } + LOG.debug("Folding expression: {} -> {}", desc, constant); return constant; } else { // Check if the function can be short cut. ExprNodeDesc shortcut = shortcutFunction(udf, newExprs, op); if (shortcut != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("Folding expression:" + desc + " -> " + shortcut); - } + LOG.debug("Folding expression: {} -> {}", desc, shortcut); return shortcut; } ((ExprNodeGenericFuncDesc) desc).setChildren(newExprs); @@ -449,15 +436,13 @@ private static ExprNodeDesc foldExprFull(ExprNodeDesc desc, Map parent = op.getParentOperators().get(tag); ExprNodeDesc col = evaluateColumn((ExprNodeColumnDesc) desc, cppCtx, parent); if (col != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("Folding expression:" + desc + " -> " + col); - } + LOG.debug("Folding expression: {} -> {}", desc, col); return col; } } @@ -467,15 +452,21 @@ private static ExprNodeDesc foldExprFull(ExprNodeDesc desc, Map children) { + private static boolean isConstantFoldableUdf(GenericUDF udf, List children) { // Runtime constants + deterministic functions can be folded. if (!FunctionRegistry.isConsistentWithinQuery(udf)) { +<<<<<<< Updated upstream if (udf.getClass().equals(GenericUDFUnixTimeStamp.class) && children != null && children.size() > 0) { // unix_timestamp is polymorphic (ignore class annotations) return true; } return false; +======= + // unix_timestamp is polymorphic (ignore class annotations) + return (udf.getClass().equals(GenericUDFUnixTimeStamp.class) + && CollectionUtils.isNotEmpty(children)); +>>>>>>> Stashed changes } // If udf is requiring additional jars, we can't determine the result in @@ -492,8 +483,8 @@ private static boolean isConstantFoldableUdf(GenericUDF udf, List files = udfInternal.getRequiredFiles(); jars = udfInternal.getRequiredJars(); } catch (Exception e) { - LOG.error("The UDF implementation class '" + udfClassName - + "' is not present in the class path"); + LOG.error("The UDF implementation class '{}' is not present in " + + "the class path", udfClassName); return false; } } else { @@ -540,9 +531,9 @@ private static void propagate(GenericUDF udf, List newExprs, RowSc } ColumnInfo ci = resolveColumn(rs, c); if (ci != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("Filter " + udf + " is identified as a value assignment, propagate it."); - } + LOG.debug( + "Filter {} is identified as a value assignment, propagate it.", + udf); if (!v.getTypeInfo().equals(ci.getType())) { v = typeCast(v, ci.getType(), true); } @@ -553,9 +544,7 @@ private static void propagate(GenericUDF udf, List newExprs, RowSc } else if (udf instanceof GenericUDFOPNull) { ExprNodeDesc operand = newExprs.get(0); if (operand instanceof ExprNodeColumnDesc) { - if (LOG.isDebugEnabled()) { - LOG.debug("Filter " + udf + " is identified as a value assignment, propagate it."); - } + LOG.debug("Filter {} is identified as a value assignment, propagate it.", udf); ExprNodeColumnDesc c = (ExprNodeColumnDesc) operand; ColumnInfo ci = resolveColumn(rs, c); if (ci != null) { @@ -573,13 +562,15 @@ private static ExprNodeDesc shortcutFunction(GenericUDF udf, List ExprNodeGenericFuncDesc caseOrWhenexpr = null; if (newExprs.get(0) instanceof ExprNodeGenericFuncDesc) { caseOrWhenexpr = (ExprNodeGenericFuncDesc) newExprs.get(0); - if (caseOrWhenexpr.getGenericUDF() instanceof GenericUDFWhen || caseOrWhenexpr.getGenericUDF() instanceof GenericUDFCase) { + if (caseOrWhenexpr.getGenericUDF() instanceof GenericUDFWhen + || caseOrWhenexpr.getGenericUDF() instanceof GenericUDFCase) { foundUDFInFirst = true; } } if (!foundUDFInFirst && newExprs.get(1) instanceof ExprNodeGenericFuncDesc) { caseOrWhenexpr = (ExprNodeGenericFuncDesc) newExprs.get(1); - if (!(caseOrWhenexpr.getGenericUDF() instanceof GenericUDFWhen || caseOrWhenexpr.getGenericUDF() instanceof GenericUDFCase)) { + if (!(caseOrWhenexpr.getGenericUDF() instanceof GenericUDFWhen + || caseOrWhenexpr.getGenericUDF() instanceof GenericUDFCase)) { return null; } } @@ -591,12 +582,12 @@ private static ExprNodeDesc shortcutFunction(GenericUDF udf, List List children = caseOrWhenexpr.getChildren(); int i; if (childUDF instanceof GenericUDFWhen) { - for (i = 1; i < children.size(); i+=2) { + for (i = 1; i < children.size(); i += 2) { children.set(i, ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPEqual(), Lists.newArrayList(children.get(i),newExprs.get(foundUDFInFirst ? 1 : 0)))); - } - if(children.size() % 2 == 1) { - i = children.size()-1; + } + if (children.size() % 2 == 1) { + i = children.size() - 1; children.set(i, ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPEqual(), Lists.newArrayList(children.get(i),newExprs.get(foundUDFInFirst ? 1 : 0)))); } @@ -606,12 +597,12 @@ private static ExprNodeDesc shortcutFunction(GenericUDF udf, List caseOrWhenexpr.getFuncText(), children); return newCaseOrWhenExpr; } else if (childUDF instanceof GenericUDFCase) { - for (i = 2; i < children.size(); i+=2) { + for (i = 2; i < children.size(); i += 2) { children.set(i, ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPEqual(), Lists.newArrayList(children.get(i),newExprs.get(foundUDFInFirst ? 1 : 0)))); } - if(children.size() % 2 == 0) { - i = children.size()-1; + if (children.size() % 2 == 0) { + i = children.size() - 1; children.set(i, ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPEqual(), Lists.newArrayList(children.get(i),newExprs.get(foundUDFInFirst ? 1 : 0)))); } @@ -760,17 +751,14 @@ private static ExprNodeDesc shortcutFunction(GenericUDF udf, List } else if(thenVal.equals(elseVal)){ return thenExpr; } else if (thenVal instanceof Boolean && elseVal instanceof Boolean) { - List children = new ArrayList<>(); - children.add(whenExpr); - children.add(new ExprNodeConstantDesc(false)); - ExprNodeGenericFuncDesc func = ExprNodeGenericFuncDesc.newInstance(new GenericUDFNvl(), - children); + ExprNodeGenericFuncDesc func = + ExprNodeGenericFuncDesc.newInstance(new GenericUDFNvl(), + Arrays.asList(whenExpr, new ExprNodeConstantDesc(false))); if (Boolean.TRUE.equals(thenVal)) { return func; } else { - List exprs = new ArrayList<>(); - exprs.add(func); - return ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPNot(), exprs); + return ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPNot(), + Collections.singletonList(func)); } } else { return null; @@ -800,30 +788,30 @@ private static ExprNodeDesc shortcutFunction(GenericUDF udf, List if (null == elseVal) { return thenExpr; } else if (op instanceof FilterOperator) { - return Boolean.TRUE.equals(elseVal) ? ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPNotEqual(), newExprs.subList(0, 2)) : - Boolean.FALSE.equals(elseVal) ? elseExpr : null; + return Boolean.TRUE.equals(elseVal) + ? ExprNodeGenericFuncDesc.newInstance( + new GenericUDFOPNotEqual(), newExprs.subList(0, 2)) + : Boolean.FALSE.equals(elseVal) ? elseExpr : null; } else { return null; } } else if (null == elseVal && op instanceof FilterOperator) { - return Boolean.TRUE.equals(thenVal) ? ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPEqual(), newExprs.subList(0, 2)) : - Boolean.FALSE.equals(thenVal) ? thenExpr : null; + return Boolean.TRUE.equals(thenVal) + ? ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPEqual(), + newExprs.subList(0, 2)) + : Boolean.FALSE.equals(thenVal) ? thenExpr : null; } else if(thenVal.equals(elseVal)){ return thenExpr; } else if (thenVal instanceof Boolean && elseVal instanceof Boolean) { ExprNodeGenericFuncDesc equal = ExprNodeGenericFuncDesc.newInstance( new GenericUDFOPEqual(), newExprs.subList(0, 2)); - List children = new ArrayList<>(); - children.add(equal); - children.add(new ExprNodeConstantDesc(false)); ExprNodeGenericFuncDesc func = ExprNodeGenericFuncDesc.newInstance(new GenericUDFNvl(), - children); + Arrays.asList(equal, new ExprNodeConstantDesc(false))); if (Boolean.TRUE.equals(thenVal)) { return func; } else { - List exprs = new ArrayList<>(); - exprs.add(func); - return ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPNot(), exprs); + return ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPNot(), + Collections.singletonList(func)); } } else { return null; @@ -855,15 +843,11 @@ private static ExprNodeDesc evaluateColumn(ExprNodeColumnDesc desc, RowSchema rs = parent.getSchema(); ColumnInfo ci = rs.getColumnInfo(desc.getColumn()); if (ci == null) { - if (LOG.isErrorEnabled()) { - LOG.error("Reverse look up of column " + desc + " error!"); - } + LOG.error("Reverse look up of column {} error", desc); ci = rs.getColumnInfo(desc.getTabAlias(), desc.getColumn()); } if (ci == null) { - if (LOG.isErrorEnabled()) { - LOG.error("Can't resolve " + desc.getTabAlias() + "." + desc.getColumn()); - } + LOG.error("Cannot resolve {}.{}", desc.getTabAlias(), desc.getColumn()); return null; } ExprNodeDesc constant = null; @@ -906,7 +890,7 @@ private static ExprNodeDesc evaluateFunction(GenericUDF udf, List for (int i = 0; i < exprs.size(); i++) { ExprNodeDesc desc = exprs.get(i); if (desc instanceof ExprNodeConstantDesc) { - ExprNodeConstantDesc constant = (ExprNodeConstantDesc) exprs.get(i); + ExprNodeConstantDesc constant = (ExprNodeConstantDesc) desc; if (!constant.getTypeInfo().equals(oldExprs.get(i).getTypeInfo())) { constant = typeCast(constant, oldExprs.get(i).getTypeInfo()); if (constant == null) { @@ -949,9 +933,8 @@ private static ExprNodeDesc evaluateFunction(GenericUDF udf, List try { ObjectInspector oi = udf.initialize(argois); Object o = udf.evaluate(arguments); - if (LOG.isDebugEnabled()) { - LOG.debug(udf.getClass().getName() + "(" + exprs + ")=" + o); - } + LOG.debug("{} ({}) = {}", udf.getClass().getName(), exprs, o); + if (o == null) { return new ExprNodeConstantDesc( TypeInfoUtils.getTypeInfoFromObjectInspector(oi), o); @@ -975,10 +958,7 @@ private static ExprNodeDesc evaluateFunction(GenericUDF udf, List return new ExprNodeConstantDesc(structType, ObjectInspectorUtils.copyToStandardJavaObject(o, coi)); } else if (!PrimitiveObjectInspectorUtils.isPrimitiveJavaClass(clz)) { - if (LOG.isErrorEnabled()) { - LOG.error("Unable to evaluate " + udf - + ". Return value unrecoginizable."); - } + LOG.error("Unable to evaluate {}. Return value unrecoginizable.", udf); return null; } else { // fall through @@ -990,8 +970,9 @@ private static ExprNodeDesc evaluateFunction(GenericUDF udf, List } return new ExprNodeConstantDesc(o).setFoldedFromVal(constStr); } catch (HiveException e) { - LOG.error("Evaluation function " + udf.getClass() - + " failed in Constant Propagation Optimizer."); + LOG.error( + "Evaluation function {} failed in Constant Propagation Optimizer", + udf.getClass(), e); throw new RuntimeException(e); } } @@ -1011,9 +992,8 @@ private static void foldOperator(Operator op, for (ColumnInfo col : schema.getSignature()) { ExprNodeDesc constant = constants.get(col); if (constant != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("Replacing column " + col + " with constant " + constant + " in " + op); - } + LOG.debug("Replacing column {} with constant {} in {}", col, constant, + op); if (!col.getType().equals(constant.getTypeInfo())) { constant = typeCast(constant, col.getType()); } @@ -1028,9 +1008,7 @@ private static void foldOperator(Operator op, if (colExprMap != null) { for (Entry e : constants.entrySet()) { String internalName = e.getKey().getInternalName(); - if (colExprMap.containsKey(internalName)) { - colExprMap.put(internalName, e.getValue()); - } + colExprMap.computeIfPresent(internalName, (k, v) -> e.getValue()); } } } @@ -1050,23 +1028,21 @@ public Object process(Node nd, Stack stack, NodeProcessorCtx ctx, Object.. ExprNodeDesc condn = op.getConf().getPredicate(); if (LOG.isDebugEnabled()) { - LOG.debug("Old filter FIL[" + op.getIdentifier() + "] conditions:" + condn.getExprString()); + LOG.debug("Old filter FIL[" + op.getIdentifier() + "] conditions: " + + condn.getExprString()); } ExprNodeDesc newCondn = foldExpr(condn, constants, cppCtx, op, 0, true); if (newCondn instanceof ExprNodeConstantDesc) { ExprNodeConstantDesc c = (ExprNodeConstantDesc) newCondn; if (Boolean.TRUE.equals(c.getValue())) { cppCtx.addOpToDelete(op); - if (LOG.isDebugEnabled()) { - LOG.debug("Filter expression " + condn + " holds true. Will delete it."); - } + LOG.debug("Filter expression {} holds true. Will delete it.", condn); } else if (Boolean.FALSE.equals(c.getValue())) { - if (LOG.isWarnEnabled()) { - LOG.warn("Filter expression " + condn + " holds false!"); - } + LOG.warn("Filter expression {} holds false!", condn); } } - if (newCondn instanceof ExprNodeConstantDesc && ((ExprNodeConstantDesc)newCondn).getValue() == null) { + if (newCondn instanceof ExprNodeConstantDesc + && ((ExprNodeConstantDesc) newCondn).getValue() == null) { // where null is same as where false newCondn = new ExprNodeConstantDesc(Boolean.FALSE); } @@ -1079,7 +1055,6 @@ public Object process(Node nd, Stack stack, NodeProcessorCtx ctx, Object.. foldOperator(op, cppCtx); return null; } - } /** @@ -1224,9 +1199,7 @@ public Object process(Node nd, Stack stack, NodeProcessorCtx ctx, Object.. columnExprMap.put(columnNames.get(i), newCol); } } - if (LOG.isDebugEnabled()) { - LOG.debug("New column list:(" + StringUtils.join(colList, " ") + ")"); - } + LOG.debug("New column list: ({})", colList); } return null; } @@ -1302,10 +1275,8 @@ public Object process(Node nd, Stack stack, NodeProcessorCtx ctx, Object.. throws SemanticException { Operator op = (Operator) nd; ConstantPropagateProcCtx cppCtx = (ConstantPropagateProcCtx) ctx; - cppCtx.getOpToConstantExprs().put(op, new HashMap()); - if (LOG.isDebugEnabled()) { - LOG.debug("Stop propagate constants on op " + op.getOperatorId()); - } + cppCtx.getOpToConstantExprs().put(op, Collections.emptyMap()); + LOG.debug("Stop propagate constants on op: {}", op); return null; } } @@ -1321,8 +1292,8 @@ public static NodeProcessor getStopProc() { */ public static class ConstantPropagateReduceSinkProc implements NodeProcessor { @Override - public Object process(Node nd, Stack stack, NodeProcessorCtx ctx, Object... nodeOutputs) - throws SemanticException { + public Object process(Node nd, Stack stack, NodeProcessorCtx ctx, + Object... nodeOutputs) throws SemanticException { ReduceSinkOperator op = (ReduceSinkOperator) nd; ReduceSinkDesc rsDesc = op.getConf(); ConstantPropagateProcCtx cppCtx = (ConstantPropagateProcCtx) ctx; @@ -1348,36 +1319,33 @@ public Object process(Node nd, Stack stack, NodeProcessorCtx ctx, Object.. && op.getChildOperators().get(0) instanceof JoinOperator) { JoinOperator joinOp = (JoinOperator) op.getChildOperators().get(0); if (skipFolding(joinOp.getConf())) { - if (LOG.isDebugEnabled()) { - LOG.debug("Skip folding in outer join " + op); - } - cppCtx.getOpToConstantExprs().put(op, new HashMap()); + LOG.debug("Skip folding in outer join {}", op); + cppCtx.getOpToConstantExprs().put(op, Collections.emptyMap()); return null; } } - if (rsDesc.getDistinctColumnIndices() != null - && !rsDesc.getDistinctColumnIndices().isEmpty()) { - if (LOG.isDebugEnabled()) { - LOG.debug("Skip folding in distinct subqueries " + op); - } - cppCtx.getOpToConstantExprs().put(op, new HashMap()); + if (CollectionUtils.isNotEmpty(rsDesc.getDistinctColumnIndices())) { + LOG.debug("Skip folding in distinct subqueries {}", op); + cppCtx.getOpToConstantExprs().put(op, Collections.emptyMap()); return null; } // key columns - ArrayList newKeyEpxrs = new ArrayList(); + ArrayList newKeyEpxrs = new ArrayList<>(); for (ExprNodeDesc desc : rsDesc.getKeyCols()) { ExprNodeDesc newDesc = foldExpr(desc, constants, cppCtx, op, 0, false); - if (newDesc != desc && desc instanceof ExprNodeColumnDesc && newDesc instanceof ExprNodeConstantDesc) { - ((ExprNodeConstantDesc)newDesc).setFoldedFromCol(((ExprNodeColumnDesc)desc).getColumn()); + if (newDesc != desc && desc instanceof ExprNodeColumnDesc + && newDesc instanceof ExprNodeConstantDesc) { + ((ExprNodeConstantDesc) newDesc) + .setFoldedFromCol(((ExprNodeColumnDesc) desc).getColumn()); } newKeyEpxrs.add(newDesc); } rsDesc.setKeyCols(newKeyEpxrs); // partition columns - ArrayList newPartExprs = new ArrayList(); + ArrayList newPartExprs = new ArrayList<>(); for (ExprNodeDesc desc : rsDesc.getPartitionCols()) { ExprNodeDesc expr = foldExpr(desc, constants, cppCtx, op, 0, false); if (expr != desc && desc instanceof ExprNodeColumnDesc @@ -1389,8 +1357,9 @@ public Object process(Node nd, Stack stack, NodeProcessorCtx ctx, Object.. rsDesc.setPartitionCols(newPartExprs); // value columns - ArrayList newValExprs = new ArrayList(); - for (ExprNodeDesc desc : rsDesc.getValueCols()) { + List valExprs = rsDesc.getValueCols(); + ArrayList newValExprs = new ArrayList<>(valExprs.size()); + for (ExprNodeDesc desc : valExprs) { newValExprs.add(foldExpr(desc, constants, cppCtx, op, 0, false)); } rsDesc.setValueCols(newValExprs); @@ -1405,15 +1374,17 @@ public Object process(Node nd, Stack stack, NodeProcessorCtx ctx, Object.. */ private boolean skipFolding(JoinDesc joinDesc) { for (JoinCondDesc cond : joinDesc.getConds()) { - if (cond.getType() == JoinDesc.INNER_JOIN || cond.getType() == JoinDesc.UNIQUE_JOIN - || cond.getType() == JoinDesc.LEFT_SEMI_JOIN) { + switch (cond.getType()) { + case JoinDesc.INNER_JOIN: + case JoinDesc.UNIQUE_JOIN: + case JoinDesc.LEFT_SEMI_JOIN: continue; + default: + return true; } - return true; } return false; } - } public static NodeProcessor getReduceSinkProc() { @@ -1445,9 +1416,7 @@ public Object process(Node nd, Stack stack, NodeProcessorCtx ctx, Object.. LOG.debug("Skip JOIN-RS structure."); return null; } - if (LOG.isInfoEnabled()) { - LOG.info("Old exprs " + conf.getExprs()); - } + LOG.debug("Old exprs: {}", conf.getExprs()); Iterator>> itr = conf.getExprs().entrySet().iterator(); while (itr.hasNext()) { Entry> e = itr.next(); @@ -1460,18 +1429,14 @@ public Object process(Node nd, Stack stack, NodeProcessorCtx ctx, Object.. for (ExprNodeDesc expr : exprs) { ExprNodeDesc newExpr = foldExpr(expr, constants, cppCtx, op, tag, false); if (newExpr instanceof ExprNodeConstantDesc) { - if (LOG.isInfoEnabled()) { - LOG.info("expr " + newExpr + " fold from " + expr + " is removed."); - } + LOG.debug("expr {} fold from {} is removed", newExpr, expr); continue; } newExprs.add(newExpr); } e.setValue(newExprs); } - if (LOG.isInfoEnabled()) { - LOG.info("New exprs " + conf.getExprs()); - } + LOG.debug("New exprs: {}", conf.getExprs()); for (List v : conf.getFilters().values()) { for (int i = 0; i < v.size(); i++) {