RexLocalRef condition = program.getCondition(); if (condition != null) { RexNode conditionNode = program.expandLocalRef(condition);
/** * 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(); }
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); } }
/** * 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(); }
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 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 public boolean matches(RelOptRuleCall call) { final Calc calc = call.rel(1); return calc.getProgram().getCondition() == null; }
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); }
/** * 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 static Expression translateCondition(RexProgram program, JavaTypeFactory typeFactory, BlockBuilder list, InputGetter inputGetter, Function1<String, InputGetter> correlates, SqlConformance conformance) { if (program.getCondition() == null) { return RexImpTable.TRUE_EXPR; } final ParameterExpression root = DataContext.ROOT; RexToLixTranslator translator = new RexToLixTranslator(program, typeFactory, root, inputGetter, list, Collections.emptyMap(), new RexBuilder(typeFactory), conformance, null, null); translator = translator.setCorrelates(correlates); return translator.translate( program.getCondition(), RexImpTable.NullAs.FALSE); }
public static Expression translateCondition(RexProgram program, JavaTypeFactory typeFactory, BlockBuilder list, InputGetter inputGetter, Function1<String, InputGetter> correlates, SqlConformance conformance) { if (program.getCondition() == null) { return RexImpTable.TRUE_EXPR; } final ParameterExpression root = DataContext.ROOT; RexToLixTranslator translator = new RexToLixTranslator(program, typeFactory, root, inputGetter, list, Collections.emptyMap(), new RexBuilder(typeFactory), conformance, null, null); translator = translator.setCorrelates(correlates); return translator.translate( program.getCondition(), RexImpTable.NullAs.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; }
@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(); } };
@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(); } };
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()) ); }
/** @see #dispatch */ public Result visit(Calc e) { Result x = visitChild(0, e.getInput()); parseCorrelTable(e, x); 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(); }
public void onMatch(RelOptRuleCall call) { final Filter topFilter = call.rel(0); final Filter bottomFilter = call.rel(1); // use RexPrograms to merge the two FilterRels into a single program // so we can convert the two LogicalFilter conditions to directly // reference the bottom LogicalFilter's child RexBuilder rexBuilder = topFilter.getCluster().getRexBuilder(); RexProgram bottomProgram = createProgram(bottomFilter); RexProgram topProgram = createProgram(topFilter); RexProgram mergedProgram = RexProgramBuilder.mergePrograms(topProgram, bottomProgram, rexBuilder); RexNode newCondition = mergedProgram.expandLocalRef(mergedProgram.getCondition()); final RelBuilder relBuilder = call.builder(); relBuilder.push(bottomFilter.getInput()).filter(newCondition); call.transformTo(relBuilder.build()); }
public void onMatch(RelOptRuleCall call) { final Filter topFilter = call.rel(0); final Filter bottomFilter = call.rel(1); // use RexPrograms to merge the two FilterRels into a single program // so we can convert the two LogicalFilter conditions to directly // reference the bottom LogicalFilter's child RexBuilder rexBuilder = topFilter.getCluster().getRexBuilder(); RexProgram bottomProgram = createProgram(bottomFilter); RexProgram topProgram = createProgram(topFilter); RexProgram mergedProgram = RexProgramBuilder.mergePrograms( topProgram, bottomProgram, rexBuilder); RexNode newCondition = mergedProgram.expandLocalRef( mergedProgram.getCondition()); final RelBuilder relBuilder = call.builder(); relBuilder.push(bottomFilter.getInput()) .filter(newCondition); call.transformTo(relBuilder.build()); }