RexLocalRef condition = program.getCondition(); if (condition != null) { RexNode conditionNode = program.expandLocalRef(condition); filterInstance = planCreator.createScalarInstance(Lists.newArrayList(conditionNode), inputRowType, StormRelUtils.getClassName(this)); List<RexLocalRef> projectList = program.getProjectList(); if (projectList != null && !projectList.isEmpty()) { List<RexNode> expandedNodes = new ArrayList<>(); for (RexLocalRef project : projectList) { expandedNodes.add(program.expandLocalRef(project));
private BlockBuilder compileToBlock(final RexProgram program, ParameterExpression context, ParameterExpression outputValues) { RelDataType inputRowType = program.getInputRowType(); final BlockBuilder builder = new BlockBuilder(); final JavaTypeFactoryImpl javaTypeFactory =
@Override public EnumerableRel implementEnumerable(List<EnumerableRel> inputs) { if (getInput() instanceof OLAPFilterRel) { // merge project & filter OLAPFilterRel filter = (OLAPFilterRel) getInput(); RelNode inputOfFilter = inputs.get(0).getInput(0); RexProgram program = RexProgram.create(inputOfFilter.getRowType(), this.rewriteProjects, filter.getCondition(), this.rowType, getCluster().getRexBuilder()); return new EnumerableCalc(getCluster(), getCluster().traitSetOf(EnumerableConvention.INSTANCE), // inputOfFilter, program); } else { // keep project for table scan EnumerableRel input = sole(inputs); RexProgram program = RexProgram.create(input.getRowType(), this.rewriteProjects, null, this.rowType, getCluster().getRexBuilder()); return new EnumerableCalc(getCluster(), getCluster().traitSetOf(EnumerableConvention.INSTANCE), // input, program); } }
/** * Returns whether this program returns its input exactly. * * <p>This is a stronger condition than {@link #projectsIdentity(boolean)}. */ public boolean isTrivial() { return getCondition() == null && projectsOnlyIdentity(); }
RexBuilder rexBuilder, boolean normalize) { assert program.isValid(Litmus.THROW, null); final RelDataType inputRowType = program.getInputRowType(); final List<RexLocalRef> projectRefs = program.getProjectList(); final RexLocalRef conditionRef = program.getCondition(); final List<RexNode> exprs = program.getExprList(); final RelDataType outputRowType = program.getOutputRowType(); return create( rexBuilder,
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 static double estimateFilteredRows(RelNode child, RexProgram program, RelMetadataQuery mq) { // convert the program's RexLocalRef condition to an expanded RexNode RexLocalRef programCondition = program.getCondition(); RexNode condition; if (programCondition == null) { condition = null; } else { condition = program.expandLocalRef(programCondition); } return estimateFilteredRows(child, condition, mq); }
@Override protected RelNode handle(RelNode rel) { if (!(rel instanceof LogicalCalc)) { return rel; } final LogicalCalc calc = (LogicalCalc) rel; final RexProgram program = calc.getProgram(); relBuilder.push(calc.getInput()); if (program.getCondition() != null) { relBuilder.filter( program.expandLocalRef(program.getCondition())); } if (!program.projectsOnlyIdentity()) { relBuilder.project( Lists.transform(program.getProjectList(), program::expandLocalRef), calc.getRowType().getFieldNames()); } return relBuilder.build(); } };
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; }
public static boolean isStar(RexProgram program) { int i = 0; for (RexLocalRef ref : program.getProjectList()) { if (ref.getIndex() != i++) { return false; } } return i == program.getInputRowType().getFieldCount(); }
/** * Returns whether this program is in canonical form. * * @param litmus What to do if an error is detected (program is not in * canonical form) * @param rexBuilder Rex builder * @return whether in canonical form */ public boolean isNormalized(Litmus litmus, RexBuilder rexBuilder) { final RexProgram normalizedProgram = normalize(rexBuilder, null); String normalized = normalizedProgram.toString(); String string = toString(); if (!normalized.equals(string)) { final String message = "Program is not normalized:\n" + "program: {}\n" + "normalized: {}\n"; return litmus.fail(message, string, normalized); } return litmus.succeed(); }
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); }
|| calc.getProgram().containsAggs()) { return; final int[] adjustments = new int[calc.getProgram().getExprCount()]; if (rightJoinChild == calc.getInput()) { int offset = leftJoinChild.getRowType().getFieldList().size(); joinRel.getRowType().getFieldList(), adjustments); if (calc.getProgram().getCondition() != null) { RexNode cond = calc.getProgram().expandLocalRef(calc.getProgram().getCondition()); final RexLocalRef rexLocalRef = topProgramBuilder.addExpr(cond.accept(rexInputConverter));
public Result visitCalc(Calc e) { Result x = visitChild(0, e.getInput()); final RexProgram program = e.getProgram(); Builder builder = program.getCondition() != null ? x.builder(e, Clause.WHERE) : x.builder(e); if (!isStar(program)) { final List<SqlNode> selectList = new ArrayList<>(); for (RexLocalRef ref : program.getProjectList()) { SqlNode sqlExpr = builder.context.toSql(program, ref); addSelect(selectList, sqlExpr, e.getRowType()); } builder.setSelect(new SqlNodeList(selectList, POS)); } if (program.getCondition() != null) { builder.setWhere( builder.context.toSql(program, program.getCondition())); } return builder.result(); }
protected RelNode makeRel(RelOptCluster cluster, RelTraitSet traitSet, RelBuilder relBuilder, RelNode input, RexProgram program) { Preconditions.checkArgument(program.getCondition() == null, "WindowedAggregateRel cannot accept a condition"); return LogicalWindow.create(cluster, traitSet, relBuilder, input, program); } }
public boolean isValid(Litmus litmus, Context context) { if (!RelOptUtil.equal( "program's input type", program.getInputRowType(), "child's output type", getInput().getRowType(), litmus)) { return litmus.fail(null); } if (!program.isValid(litmus, context)) { return litmus.fail(null); } if (!program.isNormalized(litmus, getCluster().getRexBuilder())) { return litmus.fail(null); } return litmus.succeed(); }
/** * Returns whether a program contains a multiset. */ public static boolean containsMultiset(RexProgram program) { return containsMultiset(program.getExprList(), true); }
public void onMatch(RelOptRuleCall call) { final Aggregate aggregate = call.rel(0); final Calc calc = call.rel(1); final RexProgram program = calc.getProgram(); final List<RexNode> projects = new ArrayList<>(); for (RexLocalRef localRef : program.getProjectList()) { projects.add(program.expandLocalRef(localRef)); } final Project project = LogicalProject.create(calc.getInput(), projects, calc.getRowType()); RelNode x = AggregateProjectMergeRule.apply(call, aggregate, project); if (x != null) { call.transformTo(x); } } }
/** * 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; } }
protected RelNode makeRel(RelOptCluster cluster, RelTraitSet traitSet, RelBuilder relBuilder, RelNode input, RexProgram program) { assert !program.containsAggs(); program = program.normalize(cluster.getRexBuilder(), null); return super.makeRel(cluster, traitSet, relBuilder, input, program); } },