Java Code Examples for org.apache.calcite.rel.logical.LogicalCalc#getProgram()
The following examples show how to use
org.apache.calcite.rel.logical.LogicalCalc#getProgram() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReduceDecimalsRule.java From Bats with Apache License 2.0 | 6 votes |
@Override 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); }
Example 2
Source File: SparkRules.java From calcite with Apache License 2.0 | 6 votes |
public RelNode convert(RelNode rel) { final LogicalCalc calc = (LogicalCalc) rel; // If there's a multiset, let FarragoMultisetSplitter work on it // first. final RexProgram program = calc.getProgram(); if (RexMultisetUtil.containsMultiset(program) || program.containsAggs()) { return null; } return new SparkCalc( rel.getCluster(), rel.getTraitSet().replace(SparkRel.CONVENTION), convert(calc.getInput(), calc.getInput().getTraitSet().replace(SparkRel.CONVENTION)), program); }
Example 3
Source File: FilterCalcMergeRule.java From Bats with Apache License 2.0 | 5 votes |
public void onMatch(RelOptRuleCall call) { final LogicalFilter filter = call.rel(0); final LogicalCalc calc = call.rel(1); // Don't merge a filter onto a calc which contains windowed aggregates. // That would effectively be pushing a multiset down through a filter. // We'll have chance to merge later, when the over is expanded. if (calc.getProgram().containsAggs()) { return; } // Create a program containing the filter. final RexBuilder rexBuilder = filter.getCluster().getRexBuilder(); final RexProgramBuilder progBuilder = new RexProgramBuilder( calc.getRowType(), rexBuilder); progBuilder.addIdentity(); progBuilder.addCondition(filter.getCondition()); RexProgram topProgram = progBuilder.getProgram(); RexProgram bottomProgram = calc.getProgram(); // Merge the programs together. RexProgram mergedProgram = RexProgramBuilder.mergePrograms( topProgram, bottomProgram, rexBuilder); final LogicalCalc newCalc = LogicalCalc.create(calc.getInput(), mergedProgram); call.transformTo(newCalc); }
Example 4
Source File: CalcRemoveRule.java From Bats with Apache License 2.0 | 5 votes |
public void onMatch(RelOptRuleCall call) { LogicalCalc calc = call.rel(0); RexProgram program = calc.getProgram(); if (!program.isTrivial()) { return; } RelNode input = calc.getInput(); input = call.getPlanner().register(input, calc); call.transformTo( convert( input, calc.getTraitSet())); }
Example 5
Source File: RelStructuredTypeFlattener.java From Bats with Apache License 2.0 | 5 votes |
public void rewriteRel(LogicalCalc rel) { // Translate the child. final RelNode newInput = getNewForOldRel(rel.getInput()); final RelOptCluster cluster = rel.getCluster(); RexProgramBuilder programBuilder = new RexProgramBuilder(newInput.getRowType(), cluster.getRexBuilder()); // Convert the common expressions. final RexProgram program = rel.getProgram(); final RewriteRexShuttle shuttle = new RewriteRexShuttle(); for (RexNode expr : program.getExprList()) { programBuilder.registerInput(expr.accept(shuttle)); } // Convert the projections. final List<Pair<RexNode, String>> flattenedExpList = new ArrayList<>(); List<String> fieldNames = rel.getRowType().getFieldNames(); flattenProjections(new RewriteRexShuttle(), program.getProjectList(), fieldNames, "", flattenedExpList); // Register each of the new projections. for (Pair<RexNode, String> flattenedExp : flattenedExpList) { programBuilder.addProject(flattenedExp.left, flattenedExp.right); } // Translate the condition. final RexLocalRef conditionRef = program.getCondition(); if (conditionRef != null) { final Ord<RelDataType> newField = getNewFieldForOldInput(conditionRef.getIndex()); programBuilder.addCondition(RexBuilder.getRexFactory().makeInputRef(newField.i, newField.e)); } RexProgram newProgram = programBuilder.getProgram(); // Create a new calc relational expression. LogicalCalc newRel = LogicalCalc.create(newInput, newProgram); setNewForOldRel(rel, newRel); }
Example 6
Source File: FilterCalcMergeRule.java From calcite with Apache License 2.0 | 5 votes |
public void onMatch(RelOptRuleCall call) { final LogicalFilter filter = call.rel(0); final LogicalCalc calc = call.rel(1); // Don't merge a filter onto a calc which contains windowed aggregates. // That would effectively be pushing a multiset down through a filter. // We'll have chance to merge later, when the over is expanded. if (calc.getProgram().containsAggs()) { return; } // Create a program containing the filter. final RexBuilder rexBuilder = filter.getCluster().getRexBuilder(); final RexProgramBuilder progBuilder = new RexProgramBuilder( calc.getRowType(), rexBuilder); progBuilder.addIdentity(); progBuilder.addCondition(filter.getCondition()); RexProgram topProgram = progBuilder.getProgram(); RexProgram bottomProgram = calc.getProgram(); // Merge the programs together. RexProgram mergedProgram = RexProgramBuilder.mergePrograms( topProgram, bottomProgram, rexBuilder); final LogicalCalc newCalc = LogicalCalc.create(calc.getInput(), mergedProgram); call.transformTo(newCalc); }
Example 7
Source File: ReduceDecimalsRule.java From calcite with Apache License 2.0 | 5 votes |
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); }
Example 8
Source File: CalcRemoveRule.java From calcite with Apache License 2.0 | 5 votes |
public void onMatch(RelOptRuleCall call) { LogicalCalc calc = call.rel(0); RexProgram program = calc.getProgram(); if (!program.isTrivial()) { return; } RelNode input = calc.getInput(); input = call.getPlanner().register(input, calc); call.transformTo( convert( input, calc.getTraitSet())); }
Example 9
Source File: ProjectCalcMergeRule.java From Bats with Apache License 2.0 | 4 votes |
public void onMatch(RelOptRuleCall call) { final LogicalProject project = call.rel(0); final LogicalCalc calc = call.rel(1); // Don't merge a project which contains windowed aggregates onto a // calc. That would effectively be pushing a windowed aggregate down // through a filter. Transform the project into an identical calc, // which we'll have chance to merge later, after the over is // expanded. final RelOptCluster cluster = project.getCluster(); RexProgram program = RexProgram.create( calc.getRowType(), project.getProjects(), null, project.getRowType(), cluster.getRexBuilder()); if (RexOver.containsOver(program)) { LogicalCalc projectAsCalc = LogicalCalc.create(calc, program); call.transformTo(projectAsCalc); return; } // Create a program containing the project node's expressions. final RexBuilder rexBuilder = cluster.getRexBuilder(); final RexProgramBuilder progBuilder = new RexProgramBuilder( calc.getRowType(), rexBuilder); for (Pair<RexNode, String> field : project.getNamedProjects()) { progBuilder.addProject(field.left, field.right); } RexProgram topProgram = progBuilder.getProgram(); RexProgram bottomProgram = calc.getProgram(); // Merge the programs together. RexProgram mergedProgram = RexProgramBuilder.mergePrograms( topProgram, bottomProgram, rexBuilder); final LogicalCalc newCalc = LogicalCalc.create(calc.getInput(), mergedProgram); call.transformTo(newCalc); }
Example 10
Source File: ProjectCalcMergeRule.java From calcite with Apache License 2.0 | 4 votes |
public void onMatch(RelOptRuleCall call) { final LogicalProject project = call.rel(0); final LogicalCalc calc = call.rel(1); // Don't merge a project which contains windowed aggregates onto a // calc. That would effectively be pushing a windowed aggregate down // through a filter. Transform the project into an identical calc, // which we'll have chance to merge later, after the over is // expanded. final RelOptCluster cluster = project.getCluster(); RexProgram program = RexProgram.create( calc.getRowType(), project.getProjects(), null, project.getRowType(), cluster.getRexBuilder()); if (RexOver.containsOver(program)) { LogicalCalc projectAsCalc = LogicalCalc.create(calc, program); call.transformTo(projectAsCalc); return; } // Create a program containing the project node's expressions. final RexBuilder rexBuilder = cluster.getRexBuilder(); final RexProgramBuilder progBuilder = new RexProgramBuilder( calc.getRowType(), rexBuilder); for (Pair<RexNode, String> field : project.getNamedProjects()) { progBuilder.addProject(field.left, field.right); } RexProgram topProgram = progBuilder.getProgram(); RexProgram bottomProgram = calc.getProgram(); // Merge the programs together. RexProgram mergedProgram = RexProgramBuilder.mergePrograms( topProgram, bottomProgram, rexBuilder); final LogicalCalc newCalc = LogicalCalc.create(calc.getInput(), mergedProgram); call.transformTo(newCalc); }
Example 11
Source File: RelStructuredTypeFlattener.java From calcite with Apache License 2.0 | 4 votes |
public void rewriteRel(LogicalCalc rel) { // Translate the child. final RelNode newInput = getNewForOldRel(rel.getInput()); final RelOptCluster cluster = rel.getCluster(); RexProgramBuilder programBuilder = new RexProgramBuilder( newInput.getRowType(), cluster.getRexBuilder()); // Convert the common expressions. final RexProgram program = rel.getProgram(); final RewriteRexShuttle shuttle = new RewriteRexShuttle(); for (RexNode expr : program.getExprList()) { programBuilder.registerInput(expr.accept(shuttle)); } // Convert the projections. final List<Pair<RexNode, String>> flattenedExpList = new ArrayList<>(); List<String> fieldNames = rel.getRowType().getFieldNames(); flattenProjections(new RewriteRexShuttle(), program.getProjectList(), fieldNames, "", flattenedExpList); // Register each of the new projections. for (Pair<RexNode, String> flattenedExp : flattenedExpList) { programBuilder.addProject(flattenedExp.left, flattenedExp.right); } // Translate the condition. final RexLocalRef conditionRef = program.getCondition(); if (conditionRef != null) { final Ord<RelDataType> newField = getNewFieldForOldInput(conditionRef.getIndex()); programBuilder.addCondition(new RexLocalRef(newField.i, newField.e)); } RexProgram newProgram = programBuilder.getProgram(); // Create a new calc relational expression. LogicalCalc newRel = LogicalCalc.create(newInput, newProgram); setNewForOldRel(rel, newRel); }