org.apache.calcite.rel.rules.CalcMergeRule Java Examples
The following examples show how to use
org.apache.calcite.rel.rules.CalcMergeRule.
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: ResultProcessor.java From quark with Apache License 2.0 | 6 votes |
public static String getParsedSql(RelNode relNode, SqlDialect dialect) throws SQLException { if (dialect.getDatabaseProduct() == SqlDialect.DatabaseProduct.HIVE) { final HepProgram program = new HepProgramBuilder() .addRuleInstance(JoinCalcTransposeRule.LEFT_CALC) .addRuleInstance(JoinCalcTransposeRule.RIGHT_CALC) .addRuleInstance(CalcMergeRule.INSTANCE) .build(); final RelOptPlanner planner = relNode.getCluster().getPlanner(); final HepPlanner hepPlanner = new HepPlanner(program, planner.getContext()); hepPlanner.setRoot(relNode); relNode = hepPlanner.findBestExp(); } RelToSqlConverter relToSqlConverter = new RelToSqlConverter(dialect); RelToSqlConverter.Result res = relToSqlConverter.visitChild(0, relNode); SqlNode sqlNode = res.asQuery(); String result = sqlNode.toSqlString(dialect, false).getSql(); return result.replace("\n", " "); }
Example #2
Source File: HepPlannerTest.java From calcite with Apache License 2.0 | 6 votes |
@Test void testSubprogram() throws Exception { // Verify that subprogram gets re-executed until fixpoint. // In this case, the first time through we limit it to generate // only one calc; the second time through it will generate // a second calc, and then merge them. HepProgramBuilder subprogramBuilder = HepProgram.builder(); subprogramBuilder.addMatchOrder(HepMatchOrder.TOP_DOWN); subprogramBuilder.addMatchLimit(1); subprogramBuilder.addRuleInstance(ProjectToCalcRule.INSTANCE); subprogramBuilder.addRuleInstance(FilterToCalcRule.INSTANCE); subprogramBuilder.addRuleInstance(CalcMergeRule.INSTANCE); HepProgramBuilder programBuilder = HepProgram.builder(); programBuilder.addSubprogram(subprogramBuilder.build()); final String sql = "select upper(ename) from\n" + "(select lower(ename) as ename from emp where empno = 100)"; sql(sql).with(programBuilder.build()).check(); }
Example #3
Source File: HepPlannerTest.java From calcite with Apache License 2.0 | 6 votes |
@Test void testGC() throws Exception { HepProgramBuilder programBuilder = HepProgram.builder(); programBuilder.addMatchOrder(HepMatchOrder.TOP_DOWN); programBuilder.addRuleInstance(CalcMergeRule.INSTANCE); programBuilder.addRuleInstance(ProjectToCalcRule.INSTANCE); programBuilder.addRuleInstance(FilterToCalcRule.INSTANCE); HepPlanner planner = new HepPlanner(programBuilder.build()); planner.setRoot( tester.convertSqlToRel("select upper(name) from dept where deptno=20").rel); planner.findBestExp(); // Reuse of HepPlanner (should trigger GC). planner.setRoot( tester.convertSqlToRel("select upper(name) from dept where deptno=20").rel); planner.findBestExp(); }
Example #4
Source File: MaterializedViewSubstitutionVisitorTest.java From calcite with Apache License 2.0 | 6 votes |
private RelNode canonicalize(RelNode rel) { HepProgram program = new HepProgramBuilder() .addRuleInstance(FilterProjectTransposeRule.INSTANCE) .addRuleInstance(FilterMergeRule.INSTANCE) .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN) .addRuleInstance(FilterJoinRule.JOIN) .addRuleInstance(FilterAggregateTransposeRule.INSTANCE) .addRuleInstance(ProjectMergeRule.INSTANCE) .addRuleInstance(ProjectRemoveRule.INSTANCE) .addRuleInstance(ProjectJoinTransposeRule.INSTANCE) .addRuleInstance(ProjectSetOpTransposeRule.INSTANCE) .addRuleInstance(FilterToCalcRule.INSTANCE) .addRuleInstance(ProjectToCalcRule.INSTANCE) .addRuleInstance(FilterCalcMergeRule.INSTANCE) .addRuleInstance(ProjectCalcMergeRule.INSTANCE) .addRuleInstance(CalcMergeRule.INSTANCE) .build(); final HepPlanner hepPlanner = new HepPlanner(program); hepPlanner.setRoot(rel); return hepPlanner.findBestExp(); }
Example #5
Source File: RelFieldTrimmerTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void testCalcFieldTrimmer2() { final RelBuilder builder = RelBuilder.create(config().build()); final RelNode root = builder.scan("EMP") .project(builder.field("EMPNO"), builder.field("ENAME"), builder.field("DEPTNO")) .exchange(RelDistributions.SINGLETON) .filter( builder.call(SqlStdOperatorTable.GREATER_THAN, builder.field("EMPNO"), builder.literal(100))) .project(builder.field("EMPNO"), builder.field("ENAME")) .build(); final HepProgram hepProgram = new HepProgramBuilder() .addRuleInstance(ProjectToCalcRule.INSTANCE) .addRuleInstance(FilterToCalcRule.INSTANCE) .addRuleInstance(CalcMergeRule.INSTANCE).build(); final HepPlanner hepPlanner = new HepPlanner(hepProgram); hepPlanner.setRoot(root); final RelNode relNode = hepPlanner.findBestExp(); final RelFieldTrimmer fieldTrimmer = new RelFieldTrimmer(null, builder); final RelNode trimmed = fieldTrimmer.trim(relNode); final String expected = "" + "LogicalCalc(expr#0..1=[{inputs}], expr#2=[100], expr#3=[>($t0, $t2)], proj#0." + ".1=[{exprs}], $condition=[$t3])\n" + " LogicalExchange(distribution=[single])\n" + " LogicalCalc(expr#0..1=[{inputs}], proj#0..1=[{exprs}])\n" + " LogicalProject(EMPNO=[$0], ENAME=[$1])\n" + " LogicalTableScan(table=[[scott, EMP]])\n"; assertThat(trimmed, hasTree(expected)); }
Example #6
Source File: HepPlannerTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void testGroup() throws Exception { // Verify simultaneous application of a group of rules. // Intentionally add them in the wrong order to make sure // that order doesn't matter within the group. HepProgramBuilder programBuilder = HepProgram.builder(); programBuilder.addGroupBegin(); programBuilder.addRuleInstance(CalcMergeRule.INSTANCE); programBuilder.addRuleInstance(ProjectToCalcRule.INSTANCE); programBuilder.addRuleInstance(FilterToCalcRule.INSTANCE); programBuilder.addGroupEnd(); final String sql = "select upper(name) from dept where deptno=20"; sql(sql).with(programBuilder.build()).check(); }
Example #7
Source File: RelOptMaterializations.java From calcite with Apache License 2.0 | 4 votes |
private static List<RelNode> substitute( RelNode root, RelOptMaterialization materialization) { // First, if the materialization is in terms of a star table, rewrite // the query in terms of the star table. if (materialization.starTable != null) { RelNode newRoot = RelOptMaterialization.tryUseStar(root, materialization.starRelOptTable); if (newRoot != null) { root = newRoot; } } // Push filters to the bottom, and combine projects on top. RelNode target = materialization.queryRel; // try to trim unused field in relational expressions. root = trimUnusedfields(root); target = trimUnusedfields(target); HepProgram program = new HepProgramBuilder() .addRuleInstance(FilterProjectTransposeRule.INSTANCE) .addRuleInstance(FilterMergeRule.INSTANCE) .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN) .addRuleInstance(FilterJoinRule.JOIN) .addRuleInstance(FilterAggregateTransposeRule.INSTANCE) .addRuleInstance(ProjectMergeRule.INSTANCE) .addRuleInstance(ProjectRemoveRule.INSTANCE) .addRuleInstance(ProjectJoinTransposeRule.INSTANCE) .addRuleInstance(ProjectSetOpTransposeRule.INSTANCE) .addRuleInstance(FilterToCalcRule.INSTANCE) .addRuleInstance(ProjectToCalcRule.INSTANCE) .addRuleInstance(FilterCalcMergeRule.INSTANCE) .addRuleInstance(ProjectCalcMergeRule.INSTANCE) .addRuleInstance(CalcMergeRule.INSTANCE) .build(); // We must use the same HEP planner for the two optimizations below. // Thus different nodes with the same digest will share the same vertex in // the plan graph. This is important for the matching process. final HepPlanner hepPlanner = new HepPlanner(program); hepPlanner.setRoot(target); target = hepPlanner.findBestExp(); hepPlanner.setRoot(root); root = hepPlanner.findBestExp(); return new SubstitutionVisitor(target, root).go(materialization.tableRel); }