diff --git ql/src/java/org/apache/hadoop/hive/ql/optimizer/DynamicPartitionPruningOptimization.java ql/src/java/org/apache/hadoop/hive/ql/optimizer/DynamicPartitionPruningOptimization.java index 292d375..2e4efb4 100644 --- ql/src/java/org/apache/hadoop/hive/ql/optimizer/DynamicPartitionPruningOptimization.java +++ ql/src/java/org/apache/hadoop/hive/ql/optimizer/DynamicPartitionPruningOptimization.java @@ -165,11 +165,6 @@ public Object process(Node nd, Stack stack, NodeProcessorCtx procCtx, Obje procCtx.getClass().getName()); } - FilterOperator filter = (FilterOperator) nd; - FilterDesc desc = filter.getConf(); - - TableScanOperator ts = null; - if (!parseContext.getConf().getBoolVar(ConfVars.TEZ_DYNAMIC_PARTITION_PRUNING) && !parseContext.getConf().getBoolVar(ConfVars.SPARK_DYNAMIC_PARTITION_PRUNING)) { // nothing to do when the optimization is off @@ -178,20 +173,32 @@ public Object process(Node nd, Stack stack, NodeProcessorCtx procCtx, Obje DynamicPartitionPrunerContext removerContext = new DynamicPartitionPrunerContext(); + final FilterOperator filter = (FilterOperator) nd; + final FilterDesc desc = filter.getConf(); + final ExprNodeDesc filterPredicate; + + TableScanOperator ts = null; + if (filter.getParentOperators().size() == 1 && filter.getParentOperators().get(0) instanceof TableScanOperator) { ts = (TableScanOperator) filter.getParentOperators().get(0); } + if (ts != null && ts.getConf().getFilterExpr() != null) { + filterPredicate = ts.getConf().getFilterExpr(); + } else { + filterPredicate = desc.getPredicate(); + } + if (LOG.isDebugEnabled()) { LOG.debug("Parent: " + filter.getParentOperators().get(0)); - LOG.debug("Filter: " + desc.getPredicateString()); + LOG.debug("Filter: " + filterPredicate.getExprString()); LOG.debug("TableScan: " + ts); } // collect the dynamic pruning conditions removerContext.dynLists.clear(); - walkExprTree(desc.getPredicate(), removerContext); + walkExprTree(filterPredicate, removerContext); for (DynamicListContext ctx : removerContext) { String column = extractColName(ctx.parent);