diff --git ql/src/java/org/apache/hadoop/hive/ql/ppd/OpProcFactory.java ql/src/java/org/apache/hadoop/hive/ql/ppd/OpProcFactory.java index 40298e1..4eaa807 100644 --- ql/src/java/org/apache/hadoop/hive/ql/ppd/OpProcFactory.java +++ ql/src/java/org/apache/hadoop/hive/ql/ppd/OpProcFactory.java @@ -81,6 +81,32 @@ protected static final Log LOG = LogFactory.getLog(OpProcFactory.class .getName()); + private static ExprWalkerInfo getChildWlkerInfo(Operator current, OpWalkerInfo owi) { + if (current.getNumChild() == 0) { + return null; + } + if (current.getNumChild() > 1) { + // ppd for multi-insert query is not yet implemented + // no-op for leafs + for (Operator child : current.getChildOperators()) { + removeCandidates(child, owi); // remove candidated filters on this branch + } + return null; + } + return owi.getPrunedPreds(current.getChildOperators().get(0)); + } + + private static void removeCandidates(Operator operator, OpWalkerInfo owi) { + if (operator instanceof FilterOperator) { + owi.getCandidateFilterOps().remove(operator); + } + if (operator.getChildOperators() != null) { + for (Operator child : operator.getChildOperators()) { + removeCandidates(child, owi); + } + } + } + /** * Processor for Script Operator Prevents any predicates being pushed. */ @@ -96,7 +122,8 @@ public Object process(Node nd, Stack stack, NodeProcessorCtx procCtx, // same with LIMIT op // create a filter with all children predicates OpWalkerInfo owi = (OpWalkerInfo) procCtx; - if (HiveConf.getBoolVar(owi.getParseContext().getConf(), + ExprWalkerInfo childInfo = getChildWlkerInfo((Operator) nd, owi); + if (childInfo != null && HiveConf.getBoolVar(owi.getParseContext().getConf(), HiveConf.ConfVars.HIVEPPDREMOVEDUPLICATEFILTERS)) { ExprWalkerInfo unpushedPreds = mergeChildrenPred(nd, owi, null, false); return createFilter((Operator)nd, unpushedPreds, owi); @@ -591,29 +618,16 @@ protected void logExpr(Node nd, ExprWalkerInfo ewi) { protected boolean mergeWithChildrenPred(Node nd, OpWalkerInfo owi, ExprWalkerInfo ewi, Set aliases, boolean ignoreAliases) throws SemanticException { - boolean hasUnpushedPredicates = false; - Operator current = (Operator) nd; - List> children = current.getChildOperators(); - if (children == null || children.isEmpty()) { - return hasUnpushedPredicates; - } - if (children.size() > 1) { - // ppd for multi-insert query is not yet implemented - // no-op for leafs - for (Operator child : children) { - removeCandidates(child, owi); // remove candidated filters on this branch - } - return hasUnpushedPredicates; - } - Operator op = - (Operator) nd; - ExprWalkerInfo childPreds = owi.getPrunedPreds(children.get(0)); + Operator op = (Operator) nd; + + ExprWalkerInfo childPreds = getChildWlkerInfo(op, owi); if (childPreds == null) { - return hasUnpushedPredicates; + return false; } if (ewi == null) { ewi = new ExprWalkerInfo(); } + boolean hasUnpushedPredicates = false; for (Entry> e : childPreds .getFinalCandidates().entrySet()) { if (ignoreAliases || aliases == null || aliases.contains(e.getKey()) @@ -635,17 +649,6 @@ protected boolean mergeWithChildrenPred(Node nd, OpWalkerInfo owi, return hasUnpushedPredicates; } - private void removeCandidates(Operator operator, OpWalkerInfo owi) { - if (operator instanceof FilterOperator) { - owi.getCandidateFilterOps().remove(operator); - } - if (operator.getChildOperators() != null) { - for (Operator child : operator.getChildOperators()) { - removeCandidates(child, owi); - } - } - } - protected ExprWalkerInfo mergeChildrenPred(Node nd, OpWalkerInfo owi, Set excludedAliases, boolean ignoreAliases) throws SemanticException { @@ -831,8 +834,8 @@ private static ExprNodeGenericFuncDesc pushFilterToStorageHandler( } if (decomposed.residualPredicate != null) { LOG.debug( - "Residual predicate: " - + decomposed.residualPredicate.getExprString()); + "Residual predicate: " + + decomposed.residualPredicate.getExprString()); } } tableScanDesc.setFilterExpr(decomposed.pushedPredicate); diff --git ql/src/java/org/apache/hadoop/hive/ql/ppd/PredicatePushDown.java ql/src/java/org/apache/hadoop/hive/ql/ppd/PredicatePushDown.java index cd5ae51..5e84cd6 100644 --- ql/src/java/org/apache/hadoop/hive/ql/ppd/PredicatePushDown.java +++ ql/src/java/org/apache/hadoop/hive/ql/ppd/PredicatePushDown.java @@ -105,13 +105,13 @@ public ParseContext transform(ParseContext pctx) throws SemanticException { opRules.put(new RuleRegExp("R6", ScriptOperator.getOperatorName() + "%"), OpProcFactory.getSCRProc()); - opRules.put(new RuleRegExp("R6", + opRules.put(new RuleRegExp("R7", LimitOperator.getOperatorName() + "%"), OpProcFactory.getLIMProc()); - opRules.put(new RuleRegExp("R7", + opRules.put(new RuleRegExp("R8", UDTFOperator.getOperatorName() + "%"), OpProcFactory.getUDTFProc()); - opRules.put(new RuleRegExp("R8", + opRules.put(new RuleRegExp("R9", LateralViewForwardOperator.getOperatorName() + "%"), OpProcFactory.getLVFProc());