/** * Converts a list of operands into a list that is flat with respect to * the given operator. The operands are assumed to be flat already. */ public static List<RexNode> flatten(List<? extends RexNode> exprs, SqlOperator op) { if (isFlat(exprs, op)) { //noinspection unchecked return (List) exprs; } final List<RexNode> list = new ArrayList<>(); flattenRecurse(list, exprs, op); return list; }
/** * Converts a list of operands into a list that is flat with respect to * the given operator. The operands are assumed to be flat already. */ public static List<RexNode> flatten(List<? extends RexNode> exprs, SqlOperator op) { if (isFlat(exprs, op)) { //noinspection unchecked return (List) exprs; } final List<RexNode> list = new ArrayList<>(); flattenRecurse(list, exprs, op); return list; }
/** * Creates a filter. * * @param cluster Cluster that this relational expression belongs to * @param traits the traits of this rel * @param child input relational expression * @param condition boolean expression which determines whether a row is * allowed to pass */ protected Filter( RelOptCluster cluster, RelTraitSet traits, RelNode child, RexNode condition) { super(cluster, traits, child); assert condition != null; assert RexUtil.isFlat(condition) : condition; this.condition = condition; // Too expensive for everyday use: assert !CalcitePrepareImpl.DEBUG || isValid(Litmus.THROW, null); }
/** * Creates a filter. * * @param cluster Cluster that this relational expression belongs to * @param traits the traits of this rel * @param child input relational expression * @param condition boolean expression which determines whether a row is * allowed to pass */ protected Filter( RelOptCluster cluster, RelTraitSet traits, RelNode child, RexNode condition) { super(cluster, traits, child); assert condition != null; assert RexUtil.isFlat(condition) : condition; this.condition = condition; // Too expensive for everyday use: assert !CalcitePrepareImpl.DEBUG || isValid(Litmus.THROW, null); }
/** * Returns false if the expression can be optimized by flattening * calls to an associative operator such as AND and OR. */ public static boolean isFlat(RexNode expr) { if (!(expr instanceof RexCall)) { return true; } final RexCall call = (RexCall) expr; return isFlat(call.getOperands(), call.getOperator()) && all(call.getOperands(), RexUtil::isFlat); }
/** * Returns false if the expression can be optimized by flattening * calls to an associative operator such as AND and OR. */ public static boolean isFlat(RexNode expr) { if (!(expr instanceof RexCall)) { return true; } final RexCall call = (RexCall) expr; return isFlat(call.getOperands(), call.getOperator()) && all(call.getOperands(), RexUtil::isFlat); }
/** Flattens an expression. * * <p>Returns the same expression if it is already flat. */ public static RexNode flatten(RexBuilder rexBuilder, RexNode node) { if (node instanceof RexCall) { RexCall call = (RexCall) node; final SqlOperator op = call.getOperator(); final List<RexNode> flattenedOperands = flatten(call.getOperands(), op); if (!isFlat(call.getOperands(), op)) { return rexBuilder.makeCall(call.getType(), op, flattenedOperands); } } return node; }
/** Flattens an expression. * * <p>Returns the same expression if it is already flat. */ public static RexNode flatten(RexBuilder rexBuilder, RexNode node) { if (node instanceof RexCall) { RexCall call = (RexCall) node; final SqlOperator op = call.getOperator(); final List<RexNode> flattenedOperands = flatten(call.getOperands(), op); if (!isFlat(call.getOperands(), op)) { return rexBuilder.makeCall(call.getType(), op, flattenedOperands); } } return node; }