/** * Returns whether a program contains a multiset. */ public static boolean containsMultiset(RexProgram program) { return containsMultiset(program.getExprList(), true); }
/** * Returns whether a program contains a multiset. */ public static boolean containsMultiset(RexProgram program) { return containsMultiset(program.getExprList(), true); }
/** * Returns whether a {@link RexProgram} contains expressions which require * decimal expansion. */ public static boolean requiresDecimalExpansion( RexProgram program, boolean recurse) { final List<RexNode> exprList = program.getExprList(); for (RexNode expr : exprList) { if (requiresDecimalExpansion(expr, recurse)) { return true; } } return false; }
/** * Returns whether a {@link RexProgram} contains expressions which require * decimal expansion. */ public static boolean requiresDecimalExpansion( RexProgram program, boolean recurse) { final List<RexNode> exprList = program.getExprList(); for (RexNode expr : exprList) { if (requiresDecimalExpansion(expr, recurse)) { return true; } } return false; }
@Override public void collectVariablesUsed(Set<CorrelationId> variableSet) { final RelOptUtil.VariableUsedVisitor vuv = new RelOptUtil.VariableUsedVisitor(null); for (RexNode expr : program.getExprList()) { expr.accept(vuv); } variableSet.addAll(vuv.variables); } }
@Override public void collectVariablesUsed(Set<CorrelationId> variableSet) { final RelOptUtil.VariableUsedVisitor vuv = new RelOptUtil.VariableUsedVisitor(null); for (RexNode expr : program.getExprList()) { expr.accept(vuv); } variableSet.addAll(vuv.variables); } }
/** * Returns whether a program contains an OVER clause. */ public static boolean containsOver(RexProgram program) { try { RexUtil.apply(FINDER, program.getExprList(), null); return false; } catch (OverFound e) { Util.swallow(e, null); return true; } }
/** Dereferences an expression if it is a * {@link org.apache.calcite.rex.RexLocalRef}. */ public RexNode deref(RexNode expr) { if (expr instanceof RexLocalRef) { RexLocalRef ref = (RexLocalRef) expr; final RexNode e2 = program.getExprList().get(ref.getIndex()); assert ref.getType().equals(e2.getType()); return e2; } else { return expr; } }
/** Dereferences an expression if it is a * {@link org.apache.calcite.rex.RexLocalRef}. */ public RexNode deref(RexNode expr) { if (expr instanceof RexLocalRef) { RexLocalRef ref = (RexLocalRef) expr; final RexNode e2 = program.getExprList().get(ref.getIndex()); assert ref.getType().equals(e2.getType()); return e2; } else { return expr; } }
/** * Returns whether a program contains an OVER clause. */ public static boolean containsOver(RexProgram program) { try { RexUtil.apply(FINDER, program.getExprList(), null); return false; } catch (OverFound e) { Util.swallow(e, null); return true; } }
/** * Returns true if any expression in a program contains a mixing between * multiset and non-multiset calls. */ public static boolean containsMixing(RexProgram program) { RexCallMultisetOperatorCounter counter = new RexCallMultisetOperatorCounter(); for (RexNode expr : program.getExprList()) { counter.reset(); expr.accept(counter); if ((counter.totalCount != counter.multisetCount) && (0 != counter.multisetCount)) { return true; } } return false; }
/** * Returns true if any expression in a program contains a mixing between * multiset and non-multiset calls. */ public static boolean containsMixing(RexProgram program) { RexCallMultisetOperatorCounter counter = new RexCallMultisetOperatorCounter(); for (RexNode expr : program.getExprList()) { counter.reset(); expr.accept(counter); if ((counter.totalCount != counter.multisetCount) && (0 != counter.multisetCount)) { return true; } } return false; }
private List<RexLocalRef> registerProjectsAndCondition(RexProgram program) { final List<RexNode> exprList = program.getExprList(); final List<RexLocalRef> projectRefList = new ArrayList<>(); final RexShuttle shuttle = new RegisterOutputShuttle(exprList); // For each project, lookup the expr and expand it so it is in terms of // bottomCalc's input fields for (RexLocalRef topProject : program.getProjectList()) { final RexNode topExpr = exprList.get(topProject.getIndex()); final RexLocalRef expanded = (RexLocalRef) topExpr.accept(shuttle); // Remember the expr, but don't add to the project list yet. projectRefList.add(expanded); } // Similarly for the condition. final RexLocalRef topCondition = program.getCondition(); if (topCondition != null) { final RexNode topExpr = exprList.get(topCondition.getIndex()); final RexLocalRef expanded = (RexLocalRef) topExpr.accept(shuttle); addCondition(registerInput(expanded)); } return projectRefList; }
private List<RexLocalRef> registerProjectsAndCondition(RexProgram program) { final List<RexNode> exprList = program.getExprList(); final List<RexLocalRef> projectRefList = new ArrayList<>(); final RexShuttle shuttle = new RegisterOutputShuttle(exprList); // For each project, lookup the expr and expand it so it is in terms of // bottomCalc's input fields for (RexLocalRef topProject : program.getProjectList()) { final RexNode topExpr = exprList.get(topProject.getIndex()); final RexLocalRef expanded = (RexLocalRef) topExpr.accept(shuttle); // Remember the expr, but don't add to the project list yet. projectRefList.add(expanded); } // Similarly for the condition. final RexLocalRef topCondition = program.getCondition(); if (topCondition != null) { final RexNode topExpr = exprList.get(topCondition.getIndex()); final RexLocalRef expanded = (RexLocalRef) topExpr.accept(shuttle); addCondition(registerInput(expanded)); } return projectRefList; }
/** * Returns whether this tester's <code>RelType</code> can implement a * given program. * * @param program Program * @return Whether this tester's <code>RelType</code> can implement a * given program. */ public boolean canImplement(RexProgram program) { if ((program.getCondition() != null) && !canImplement(program.getCondition(), true)) { return false; } for (RexNode expr : program.getExprList()) { if (!canImplement(expr, false)) { return false; } } return true; } }
/** * Returns whether this tester's <code>RelType</code> can implement a * given program. * * @param program Program * @return Whether this tester's <code>RelType</code> can implement a * given program. */ public boolean canImplement(RexProgram program) { if ((program.getCondition() != null) && !canImplement(program.getCondition(), true)) { return false; } for (RexNode expr : program.getExprList()) { if (!canImplement(expr, false)) { return false; } } return true; } }
public RexProgram copyOf(RexProgram program) { return new RexProgram( copyOf(program.getInputRowType()), copyRexNodes(program.getExprList()), Lists.transform(program.getProjectList(), COPY_REX_LOCAL_REF), (RexLocalRef) copyOf(program.getCondition()), copyOf(program.getOutputRowType()) ); }
public RelNode accept(RexShuttle shuttle) { List<RexNode> oldExprs = program.getExprList(); List<RexNode> exprs = shuttle.apply(oldExprs); List<RexLocalRef> oldProjects = program.getProjectList(); List<RexLocalRef> projects = shuttle.apply(oldProjects); RexLocalRef oldCondition = program.getCondition(); RexNode condition; if (oldCondition != null) { condition = shuttle.apply(oldCondition); assert condition instanceof RexLocalRef : "Invalid condition after rewrite. Expected RexLocalRef, got " + condition; } else { condition = null; } if (exprs == oldExprs && projects == oldProjects && condition == oldCondition) { return this; } return copy(traitSet, getInput(), new RexProgram(program.getInputRowType(), exprs, projects, (RexLocalRef) condition, program.getOutputRowType())); } }
public void onMatch(RelOptRuleCall call) { LogicalCalc calc = call.rel(0); // Expand decimals in every expression in this program. If no // expression changes, don't apply the rule. final RexProgram program = calc.getProgram(); if (!RexUtil.requiresDecimalExpansion(program, true)) { return; } final RexBuilder rexBuilder = calc.getCluster().getRexBuilder(); final RexShuttle shuttle = new DecimalShuttle(rexBuilder); RexProgramBuilder programBuilder = RexProgramBuilder.create( rexBuilder, calc.getInput().getRowType(), program.getExprList(), program.getProjectList(), program.getCondition(), program.getOutputRowType(), shuttle, true); final RexProgram newProgram = programBuilder.getProgram(); LogicalCalc newCalc = LogicalCalc.create(calc.getInput(), newProgram); call.transformTo(newCalc); }
public void onMatch(RelOptRuleCall call) { LogicalCalc calc = call.rel(0); // Expand decimals in every expression in this program. If no // expression changes, don't apply the rule. final RexProgram program = calc.getProgram(); if (!RexUtil.requiresDecimalExpansion(program, true)) { return; } final RexBuilder rexBuilder = calc.getCluster().getRexBuilder(); final RexShuttle shuttle = new DecimalShuttle(rexBuilder); RexProgramBuilder programBuilder = RexProgramBuilder.create( rexBuilder, calc.getInput().getRowType(), program.getExprList(), program.getProjectList(), program.getCondition(), program.getOutputRowType(), shuttle, true); final RexProgram newProgram = programBuilder.getProgram(); LogicalCalc newCalc = LogicalCalc.create(calc.getInput(), newProgram); call.transformTo(newCalc); }