/** * Converts a WHERE clause. * * @param bb Blackboard * @param where WHERE clause, may be null */ private void convertWhere( final Blackboard bb, final SqlNode where) { if (where == null) { return; } SqlNode newWhere = pushDownNotForIn(where); replaceSubqueries(bb, newWhere, RelOptUtil.Logic.UNKNOWN_AS_FALSE); final RexNode convertedWhere = bb.convertExpression(newWhere); // only allocate filter if the condition is not TRUE if (!convertedWhere.isAlwaysTrue()) { bb.setRoot( RelOptUtil.createFilter(bb.root, convertedWhere), false); } }
/** * Returns a guess for the selectivity of an expression. * * @param exp expression of interest, or null for none (implying a * selectivity of 1.0) * @return guessed selectivity */ public static double getSelectivity(RexNode exp) { if ((exp == null) || exp.isAlwaysTrue()) { return 1d; } return 0.1d; }
public boolean apply(RexNode e) { return !e.isAlwaysTrue(); } };
/** * Returns a guess for the selectivity of an expression. * * @param exp expression of interest, or null for none (implying a * selectivity of 1.0) * * @return guessed selectivity */ public static double getSelectivity(RexNode exp) { if ((exp == null) || exp.isAlwaysTrue()) { return 1; } return 0.1; }
replaceSubqueries(bb, newHaving, RelOptUtil.Logic.UNKNOWN_AS_FALSE); havingExpr = bb.convertExpression(newHaving); if (havingExpr.isAlwaysTrue()) { havingExpr = null;
protected NonEquiJoinInfo(ImmutableIntList leftKeys, ImmutableIntList rightKeys, RexNode remaining) { super(leftKeys, rightKeys); this.remaining = Preconditions.checkNotNull(remaining); assert !remaining.isAlwaysTrue(); }
public CascadingJoinRel( RelOptCluster cluster, RelTraitSet traits, RelNode left, RelNode right, RexNode condition, JoinRelType joinType, Set<String> variablesStopped, int hash ) { super( cluster, traits, left, right, condition, joinType, variablesStopped ); this.hash = hash; RexNode remaining = RelOptUtil.splitJoinCondition( left, right, condition, leftKeys, rightKeys ); // Rule should have checked "isEqui" before firing. Something went wrong. if( !remaining.isAlwaysTrue() ) throw new AssertionError( "not equi-join condition: " + remaining ); }
/** * Sets bitmaps indicating which factors and fields each join filter * references */ private void setJoinFilterRefs() { fieldsRefByJoinFilter = new HashMap<RexNode, BitSet>(); factorsRefByJoinFilter = new HashMap<RexNode, BitSet>(); ListIterator<RexNode> filterIter = allJoinFilters.listIterator(); while (filterIter.hasNext()) { RexNode joinFilter = filterIter.next(); // ignore the literal filter; if necessary, we'll add it back // later if (joinFilter.isAlwaysTrue()) { filterIter.remove(); } BitSet factorRefBitmap = getJoinFilterFactorBitmap(joinFilter, true); factorsRefByJoinFilter.put(joinFilter, factorRefBitmap); } }
/** * Makes a reinterpret cast. * * @param type type returned by the cast * @param exp expression to be casted * @param checkOverflow whether an overflow check is required * @return a RexCall with two operands and a special return type */ public RexNode makeReinterpretCast( RelDataType type, RexNode exp, RexNode checkOverflow) { List<RexNode> args; if ((checkOverflow != null) && checkOverflow.isAlwaysTrue()) { args = ImmutableList.of(exp, checkOverflow); } else { args = ImmutableList.of(exp); } return new RexCall( type, SqlStdOperatorTable.REINTERPRET, args); }
/** Combines a collection of predicates using AND. Returns TRUE if the * collection is empty. */ public static RexNode composeConjunction( RexBuilder rexBuilder, List<RexNode> nodes) { RexNode node = null; for (RexNode node1 : nodes) { if (node1.isAlwaysTrue()) { continue; } if (node == null) { node = node1; } else { node = rexBuilder.makeCall( SqlStdOperatorTable.andOperator, node, node1); } } return node == null ? rexBuilder.makeLiteral(true) : node; }
/** * If the filter list passed in is non-empty, creates a FilterRel on top of * the existing RelNode; otherwise, just returns the RelNode * * @param rexBuilder rex builder * @param rel the RelNode that the filter will be put on top of * @param filters list of filters * @return new RelNode or existing one if no filters */ private RelNode createFilterOnRel( RexBuilder rexBuilder, RelNode rel, List<RexNode> filters) { RexNode andFilters = RexUtil.composeConjunction(rexBuilder, filters, false); if (andFilters.isAlwaysTrue()) { return rel; } return filterFactory.createFilter(rel, andFilters); }
/** * Decompose a rex predicate into list of RexNodes that are AND'ed together * * @param rexPredicate predicate to be analyzed * @param rexList list of decomposed RexNodes */ public static void decomposeConjunction( RexNode rexPredicate, List<RexNode> rexList) { if (rexPredicate == null || rexPredicate.isAlwaysTrue()) { return; } if (rexPredicate.isA(RexKind.And)) { for (RexNode operand : ((RexCall) rexPredicate).getOperands()) { decomposeConjunction(operand, rexList); } } else { rexList.add(rexPredicate); } }
/** * Decomposes a predicate into a list of expressions that are AND'ed * together. * * @param rexPredicate predicate to be analyzed * @param rexList list of decomposed RexNodes */ public static void decomposeConjunction( RexNode rexPredicate, List<RexNode> rexList) { if (rexPredicate == null || rexPredicate.isAlwaysTrue()) { return; } if (rexPredicate.isA(SqlKind.AND)) { for (RexNode operand : ((RexCall) rexPredicate).getOperands()) { decomposeConjunction(operand, rexList); } } else { rexList.add(rexPredicate); } }
private boolean isAlwaysTrue(RexNode predicate) { if (predicate instanceof RexCall) { RexCall c = (RexCall) predicate; if (c.getOperator().getKind() == SqlKind.EQUALS) { int lPos = pos(c.getOperands().get(0)); int rPos = pos(c.getOperands().get(1)); return lPos != -1 && lPos == rPos; } } return predicate.isAlwaysTrue(); } }
public RexNode apply(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); } };
protected JdbcJoinRel( RelOptCluster cluster, RelTraitSet traits, RelNode left, RelNode right, RexNode condition, JoinRelType joinType, Set<String> variablesStopped) throws InvalidRelException { super( cluster, traits, left, right, condition, joinType, variablesStopped); final List<Integer> leftKeys = new ArrayList<Integer>(); final List<Integer> rightKeys = new ArrayList<Integer>(); RexNode remaining = RelOptUtil.splitJoinCondition( left, right, condition, leftKeys, rightKeys); if (!remaining.isAlwaysTrue()) { throw new InvalidRelException( "JdbcJoinRel only supports equi-join"); } this.leftKeys = ImmutableIntList.copyOf(leftKeys); this.rightKeys = ImmutableIntList.copyOf(rightKeys); }
/** Creates a {@code JoinInfo} by analyzing a condition. */ public static JoinInfo of(RelNode left, RelNode right, RexNode condition) { final List<Integer> leftKeys = new ArrayList<Integer>(); final List<Integer> rightKeys = new ArrayList<Integer>(); RexNode remaining = RelOptUtil.splitJoinCondition(left, right, condition, leftKeys, rightKeys); if (remaining.isAlwaysTrue()) { return new EquiJoinInfo(ImmutableIntList.copyOf(leftKeys), ImmutableIntList.copyOf(rightKeys)); } else { return new NonEquiJoinInfo(ImmutableIntList.copyOf(leftKeys), ImmutableIntList.copyOf(rightKeys), remaining); } }
MutableFilter createFilter(MutableFilter query, MutableFilter target) { final RexNode newCondition = splitFilter(query.cluster.getRexBuilder(), query.getCondition(), target.getCondition()); if (newCondition == null) { // Could not map query onto target. return null; } if (newCondition.isAlwaysTrue()) { return target; } return MutableFilter.of(target, newCondition); } }
if (!convertedWhere.isAlwaysTrue()) { RelNode inputRel = bb.root; Set<String> correlatedVariablesBefore =
/** * Converts a WHERE clause. * * @param bb Blackboard * @param where WHERE clause, may be null */ private void convertWhere( final Blackboard bb, final SqlNode where) { if (where == null) { return; } SqlNode newWhere = pushDownNotForIn(where); replaceSubqueries(bb, newWhere); final RexNode convertedWhere = bb.convertExpression(newWhere); // only allocate filter if the condition is not TRUE if (!convertedWhere.isAlwaysTrue()) { bb.setRoot( CalcRel.createFilter(bb.root, convertedWhere), false); } }