Java Code Examples for org.apache.calcite.rel.logical.LogicalCalc#create()
The following examples show how to use
org.apache.calcite.rel.logical.LogicalCalc#create() .
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: ProjectToCalcRule.java From Bats with Apache License 2.0 | 5 votes |
public void onMatch(RelOptRuleCall call) { final LogicalProject project = call.rel(0); final RelNode input = project.getInput(); final RexProgram program = RexProgram.create( input.getRowType(), project.getProjects(), null, project.getRowType(), project.getCluster().getRexBuilder()); final LogicalCalc calc = LogicalCalc.create(input, program); call.transformTo(calc); }
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: 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 5
Source File: ProjectToCalcRule.java From calcite with Apache License 2.0 | 5 votes |
public void onMatch(RelOptRuleCall call) { final LogicalProject project = call.rel(0); final RelNode input = project.getInput(); final RexProgram program = RexProgram.create( input.getRowType(), project.getProjects(), null, project.getRowType(), project.getCluster().getRexBuilder()); final LogicalCalc calc = LogicalCalc.create(input, program); call.transformTo(calc); }
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: RelMetadataTest.java From calcite with Apache License 2.0 | 5 votes |
@Nonnull private Function<String, RelNode> convertProjectAsCalc() { return s -> { Project project = (Project) convertSql(s); RexProgram program = RexProgram.create( project.getInput().getRowType(), project.getProjects(), null, project.getRowType(), project.getCluster().getRexBuilder()); return LogicalCalc.create(project.getInput(), program); }; }
Example 9
Source File: RelWriterTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void testCalc() { final FrameworkConfig config = RelBuilderTest.config().build(); final RelBuilder builder = RelBuilder.create(config); final RexBuilder rexBuilder = builder.getRexBuilder(); final LogicalTableScan scan = (LogicalTableScan) builder.scan("EMP").build(); final RexProgramBuilder programBuilder = new RexProgramBuilder(scan.getRowType(), rexBuilder); final RelDataTypeField field = scan.getRowType().getField("SAL", false, false); programBuilder.addIdentity(); programBuilder.addCondition( rexBuilder.makeCall(SqlStdOperatorTable.GREATER_THAN, new RexInputRef(field.getIndex(), field.getType()), builder.literal(10))); final LogicalCalc calc = LogicalCalc.create(scan, programBuilder.getProgram()); String relJson = RelOptUtil.dumpPlan("", calc, SqlExplainFormat.JSON, SqlExplainLevel.EXPPLAN_ATTRIBUTES); String s = Frameworks.withPlanner((cluster, relOptSchema, rootSchema) -> { final RelJsonReader reader = new RelJsonReader( cluster, getSchema(calc), rootSchema); RelNode node; try { node = reader.read(relJson); } catch (IOException e) { throw TestUtil.rethrow(e); } return RelOptUtil.dumpPlan("", node, SqlExplainFormat.TEXT, SqlExplainLevel.EXPPLAN_ATTRIBUTES); }); final String expected = "LogicalCalc(expr#0..7=[{inputs}], expr#8=[10], expr#9=[>($t5, $t8)]," + " proj#0..7=[{exprs}], $condition=[$t9])\n" + " LogicalTableScan(table=[[scott, EMP]])\n"; assertThat(s, isLinux(expected)); }
Example 10
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 11
Source File: CalcRelSplitter.java From Bats with Apache License 2.0 | 4 votes |
protected RelNode makeRel(RelOptCluster cluster, RelTraitSet traitSet, RelBuilder relBuilder, RelNode input, RexProgram program) { return LogicalCalc.create(input, program); }
Example 12
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 13
Source File: CalcRelSplitter.java From calcite with Apache License 2.0 | 4 votes |
protected RelNode makeRel(RelOptCluster cluster, RelTraitSet traitSet, RelBuilder relBuilder, RelNode input, RexProgram program) { return LogicalCalc.create(input, program); }
Example 14
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); }