diff --git a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/DynamicPartitionPruningOptimization.java b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/DynamicPartitionPruningOptimization.java index 6686273b14..374004f309 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/DynamicPartitionPruningOptimization.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/DynamicPartitionPruningOptimization.java @@ -157,10 +157,14 @@ public Object process(Node nd, Stack stack, NodeProcessorCtx procCtx, Obje semiJoin = false; } + List newBetweenNodes = new ArrayList<>(); + List newBloomFilterNodes = new ArrayList<>(); for (DynamicListContext ctx : removerContext) { String column = ExprNodeDescUtils.extractColName(ctx.parent); boolean semiJoinAttempted = false; + ExprNodeDesc constNode = + new ExprNodeConstantDesc(ctx.parent.getTypeInfo(), true); if (column != null) { // Need unique IDs to refer to each min/max key value in the DynamicValueRegistry String keyBaseAlias = ""; @@ -265,22 +269,29 @@ public Object process(Node nd, Stack stack, NodeProcessorCtx procCtx, Obje ExprNodeDesc bloomFilterNode = ExprNodeGenericFuncDesc.newInstance( FunctionRegistry.getFunctionInfo("in_bloom_filter"). getGenericUDF(), bloomFilterArgs); - List andArgs = new ArrayList(); - andArgs.add(betweenNode); - andArgs.add(bloomFilterNode); - ExprNodeDesc andExpr = ExprNodeGenericFuncDesc.newInstance( - FunctionRegistry.getFunctionInfo("and").getGenericUDF(), andArgs); - replaceExprNode(ctx, desc, andExpr); - } else { - ExprNodeDesc replaceNode = new ExprNodeConstantDesc(ctx.parent.getTypeInfo(), true); - replaceExprNode(ctx, desc, replaceNode); + newBetweenNodes.add(betweenNode); + newBloomFilterNodes.add(bloomFilterNode); } + } + replaceExprNode(ctx, desc, constNode); + } + + if (!newBetweenNodes.isEmpty()) { + // We need to add the new nodes: first the between nodes, then the bloom filters + if (FunctionRegistry.isOpAnd(desc.getPredicate())) { // AND + desc.getPredicate().getChildren().addAll(newBetweenNodes); + desc.getPredicate().getChildren().addAll(newBloomFilterNodes); } else { - ExprNodeDesc constNode = - new ExprNodeConstantDesc(ctx.parent.getTypeInfo(), true); - replaceExprNode(ctx, desc, constNode); + List andArgs = new ArrayList<>(); + andArgs.add(desc.getPredicate()); + andArgs.addAll(newBetweenNodes); + andArgs.addAll(newBloomFilterNodes); + ExprNodeDesc andExpr = ExprNodeGenericFuncDesc.newInstance( + FunctionRegistry.getFunctionInfo("and").getGenericUDF(), andArgs); + desc.setPredicate(andExpr); } } + // if we pushed the predicate into the table scan we need to remove the // synthetic conditions there. cleanTableScanFilters(ts);