/** * Translates "condition" to a Druid filter, assuming it does not contain any boolean expressions. Returns null * if we cannot translate the condition. * * @param plannerContext planner context * @param rowSignature row signature of the dataSource to be filtered * @param rexNode Calcite row expression */ @Nullable private static DimFilter toLeafFilter( final PlannerContext plannerContext, final RowSignature rowSignature, final RexNode rexNode ) { if (rexNode.isAlwaysTrue()) { return Filtration.matchEverything(); } else if (rexNode.isAlwaysFalse()) { return Filtration.matchNothing(); } final DimFilter simpleFilter = toSimpleLeafFilter(plannerContext, rowSignature, rexNode); return simpleFilter != null ? simpleFilter : toExpressionLeafFilter(plannerContext, rowSignature, rexNode); }
/** Creates a {@link org.apache.calcite.rel.core.Filter} of a list of * predicates. * * <p>The predicates are combined using AND, * and optimized in a similar way to the {@link #and} method. * If the result is TRUE no filter is created. */ public HiveSubQRemoveRelBuilder filter(Iterable<? extends RexNode> predicates) { final RexNode x = RexUtil.simplifyAnds(cluster.getRexBuilder(), predicates, true); if (x.isAlwaysFalse()) { return empty(); } if (!x.isAlwaysTrue()) { final Frame frame = stack.pop(); final RelNode filter = filterFactory.createFilter(frame.rel, x); stack.push(new Frame(filter, frame.right)); } return this; }
/** Creates a {@link org.apache.calcite.rel.core.Filter} of a list of * predicates. * * <p>The predicates are combined using AND, * and optimized in a similar way to the {@link #and} method. * If the result is TRUE no filter is created. */ public HiveSubQRemoveRelBuilder filter(Iterable<? extends RexNode> predicates) { final RexNode x = RexUtil.simplifyAnds(cluster.getRexBuilder(), predicates, true); if (x.isAlwaysFalse()) { return empty(); } if (!x.isAlwaysTrue()) { final Frame frame = stack.pop(); final RelNode filter = filterFactory.createFilter(frame.rel, x); stack.push(new Frame(filter, frame.right)); } return this; }
maxMinStats.get(j).left, maxMinStats.get(j).right); if (reduced != null) { if (reduced.isAlwaysFalse()) { allTrue = false; addOperand = false;
new RexSimplify(rexBuilder, true, executor); final RexNode x = simplify.simplifyAnds(listBuilder.build()); if (x.isAlwaysFalse()) {
maxMinStats.get(j).left, maxMinStats.get(j).right); if (reduced != null) { if (reduced.isAlwaysFalse()) { allTrue = false; addOperand = false;
private static boolean containsFalse(Iterable<RexNode> nodes) { for (RexNode node : nodes) { if (node.isAlwaysFalse()) { return true; } } return false; }
private static boolean containsFalse(Iterable<RexNode> nodes) { for (RexNode node : nodes) { if (node.isAlwaysFalse()) { return true; } } return false; }
private static void addOr(ImmutableList.Builder<RexNode> builder, Set<RexNode> set, RexNode node) { switch (node.getKind()) { case OR: for (RexNode operand : ((RexCall) node).getOperands()) { addOr(builder, set, operand); } return; default: if (!node.isAlwaysFalse() && set.add(node)) { builder.add(node); } } }
@Override public boolean isAlwaysFalse() { switch (getKind()) { case IS_NULL: return !operands.get(0).getType().isNullable(); case IS_NOT_TRUE: case IS_FALSE: case NOT: return operands.get(0).isAlwaysTrue(); case IS_NOT_FALSE: case IS_TRUE: case CAST: return operands.get(0).isAlwaysFalse(); default: return false; } }
@Override public boolean isAlwaysFalse() { switch (getKind()) { case IS_NULL: return !operands.get(0).getType().isNullable(); case IS_NOT_TRUE: case IS_FALSE: case NOT: return operands.get(0).isAlwaysTrue(); case IS_NOT_FALSE: case IS_TRUE: case CAST: return operands.get(0).isAlwaysFalse(); default: return false; } }
private static void addOr(ImmutableList.Builder<RexNode> builder, Set<String> digests, RexNode node) { switch (node.getKind()) { case OR: for (RexNode operand : ((RexCall) node).getOperands()) { addOr(builder, digests, operand); } return; default: if (!node.isAlwaysFalse() && digests.add(node.toString())) { builder.add(node); } } }
@Override public boolean isAlwaysTrue() { // "c IS NOT NULL" occurs when we expand EXISTS. // This reduction allows us to convert it to a semi-join. switch (getKind()) { case IS_NOT_NULL: return !operands.get(0).getType().isNullable(); case IS_NOT_TRUE: case IS_FALSE: case NOT: return operands.get(0).isAlwaysFalse(); case IS_NOT_FALSE: case IS_TRUE: case CAST: return operands.get(0).isAlwaysTrue(); default: return false; } }
public Double getMaxRowCount(Filter rel, RelMetadataQuery mq) { if (rel.getCondition().isAlwaysFalse()) { return 0D; } return mq.getMaxRowCount(rel.getInput()); }
public Double getMaxRowCount(Filter rel, RelMetadataQuery mq) { if (rel.getCondition().isAlwaysFalse()) { return 0D; } return mq.getMaxRowCount(rel.getInput()); }
/** Applies NOT to an expression. */ static RexNode not(final RexBuilder rexBuilder, RexNode input) { return input.isAlwaysTrue() ? rexBuilder.makeLiteral(false) : input.isAlwaysFalse() ? rexBuilder.makeLiteral(true) : input.getKind() == SqlKind.NOT ? ((RexCall) input).operands.get(0) : rexBuilder.makeCall(SqlStdOperatorTable.NOT, input); }
/** Applies NOT to an expression. */ static RexNode not(final RexBuilder rexBuilder, RexNode input) { return input.isAlwaysTrue() ? rexBuilder.makeLiteral(false) : input.isAlwaysFalse() ? rexBuilder.makeLiteral(true) : input.getKind() == SqlKind.NOT ? ((RexCall) input).operands.get(0) : rexBuilder.makeCall(SqlStdOperatorTable.NOT, input); }
public boolean matches(RelOptRuleCall call) { Preconditions.checkArgument(call.rel(1) instanceof Join); Join join = call.rel(1); return !(join.getCondition().isAlwaysTrue() || join.getCondition().isAlwaysFalse()); } };
/** Checks that {@link RexNode#isAlwaysTrue()}, * {@link RexNode#isAlwaysTrue()} and {@link RexSimplify} agree that * an expression reduces to true or false. */ private void checkIs(RexNode e, boolean expected) { assertThat("isAlwaysTrue() of expression: " + e.toString(), e.isAlwaysTrue(), is(expected)); assertThat("isAlwaysFalse() of expression: " + e.toString(), e.isAlwaysFalse(), is(!expected)); assertThat("Simplification is not using isAlwaysX informations", simplify(e).toString(), is(expected ? "true" : "false")); }
/** Checks that {@link RexNode#isAlwaysTrue()}, * {@link RexNode#isAlwaysTrue()} and {@link RexSimplify} agree that * an expression reduces to true or false. */ private void checkIs(RexNode e, boolean expected) { assertThat("isAlwaysTrue() of expression: " + e.toString(), e.isAlwaysTrue(), is(expected)); assertThat("isAlwaysFalse() of expression: " + e.toString(), e.isAlwaysFalse(), is(!expected)); assertThat("Simplification is not using isAlwaysX informations", simplify(e).toString(), is(expected ? "true" : "false")); }