org.apache.calcite.rel.rules.ProjectMergeRule Java Examples
The following examples show how to use
org.apache.calcite.rel.rules.ProjectMergeRule.
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: RelOptMaterialization.java From Bats with Apache License 2.0 | 6 votes |
/** * Converts a relational expression to a form where * {@link org.apache.calcite.rel.logical.LogicalJoin}s are * as close to leaves as possible. */ public static RelNode toLeafJoinForm(RelNode rel) { final Program program = Programs.hep( ImmutableList.of( JoinProjectTransposeRule.RIGHT_PROJECT, JoinProjectTransposeRule.LEFT_PROJECT, FilterJoinRule.FilterIntoJoinRule.FILTER_ON_JOIN, ProjectRemoveRule.INSTANCE, ProjectMergeRule.INSTANCE), false, DefaultRelMetadataProvider.INSTANCE); if (CalciteSystemProperty.DEBUG.value()) { System.out.println( RelOptUtil.dumpPlan("before", rel, SqlExplainFormat.TEXT, SqlExplainLevel.DIGEST_ATTRIBUTES)); } final RelNode rel2 = program.run(null, rel, null, ImmutableList.of(), ImmutableList.of()); if (CalciteSystemProperty.DEBUG.value()) { System.out.println( RelOptUtil.dumpPlan("after", rel2, SqlExplainFormat.TEXT, SqlExplainLevel.DIGEST_ATTRIBUTES)); } return rel2; }
Example #2
Source File: RelOptMaterialization.java From calcite with Apache License 2.0 | 6 votes |
/** * Converts a relational expression to a form where * {@link org.apache.calcite.rel.logical.LogicalJoin}s are * as close to leaves as possible. */ public static RelNode toLeafJoinForm(RelNode rel) { final Program program = Programs.hep( ImmutableList.of( JoinProjectTransposeRule.RIGHT_PROJECT, JoinProjectTransposeRule.LEFT_PROJECT, FilterJoinRule.FilterIntoJoinRule.FILTER_ON_JOIN, ProjectRemoveRule.INSTANCE, ProjectMergeRule.INSTANCE), false, DefaultRelMetadataProvider.INSTANCE); if (CalciteSystemProperty.DEBUG.value()) { System.out.println( RelOptUtil.dumpPlan("before", rel, SqlExplainFormat.TEXT, SqlExplainLevel.DIGEST_ATTRIBUTES)); } final RelNode rel2 = program.run(null, rel, null, ImmutableList.of(), ImmutableList.of()); if (CalciteSystemProperty.DEBUG.value()) { System.out.println( RelOptUtil.dumpPlan("after", rel2, SqlExplainFormat.TEXT, SqlExplainLevel.DIGEST_ATTRIBUTES)); } return rel2; }
Example #3
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 #4
Source File: RelOptMaterializations.java From Bats with Apache License 2.0 | 5 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; HepProgram program = new HepProgramBuilder() .addRuleInstance(FilterProjectTransposeRule.INSTANCE) .addRuleInstance(ProjectMergeRule.INSTANCE) .addRuleInstance(ProjectRemoveRule.INSTANCE) .build(); final HepPlanner hepPlanner = new HepPlanner(program); hepPlanner.setRoot(target); target = hepPlanner.findBestExp(); hepPlanner.setRoot(root); root = hepPlanner.findBestExp(); return new MaterializedViewSubstitutionVisitor(target, root) .go(materialization.tableRel); }
Example #5
Source File: MaterializedViewAggregateRule.java From calcite with Apache License 2.0 | 5 votes |
/** Creates a MaterializedViewAggregateRule. */ protected MaterializedViewAggregateRule(RelOptRuleOperand operand, RelBuilderFactory relBuilderFactory, String description, boolean generateUnionRewriting, HepProgram unionRewritingPullProgram) { this(operand, relBuilderFactory, description, generateUnionRewriting, unionRewritingPullProgram, new FilterProjectTransposeRule( Filter.class, Project.class, true, true, relBuilderFactory), new FilterAggregateTransposeRule( Filter.class, relBuilderFactory, Aggregate.class), new AggregateProjectPullUpConstantsRule( Aggregate.class, Filter.class, relBuilderFactory, "AggFilterPullUpConstants"), new ProjectMergeRule(true, ProjectMergeRule.DEFAULT_BLOAT, relBuilderFactory)); }
Example #6
Source File: PlannerTest.java From calcite with Apache License 2.0 | 5 votes |
/** Test case for * <a href="https://issues.apache.org/jira/browse/CALCITE-648">[CALCITE-648] * Update ProjectMergeRule description for new naming convention</a>. */ @Test void testMergeProjectForceMode() throws Exception { RuleSet ruleSet = RuleSets.ofList( new ProjectMergeRule(true, ProjectMergeRule.DEFAULT_BLOAT, RelBuilder.proto(RelFactories.DEFAULT_PROJECT_FACTORY))); Planner planner = getPlanner(null, Programs.of(ruleSet)); planner.close(); }
Example #7
Source File: MutableRelTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void testConvertSemiJoin() { final String sql = "select * from dept where exists (\n" + " select * from emp\n" + " where emp.deptno = dept.deptno\n" + " and emp.sal > 100)"; checkConvertMutableRel( "Join", // with join type as semi sql, true, ImmutableList.of( FilterProjectTransposeRule.INSTANCE, FilterJoinRule.FILTER_ON_JOIN, ProjectMergeRule.INSTANCE, SemiJoinRule.PROJECT)); }
Example #8
Source File: SqlHintsConverterTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void testHintsPropagationInVolcanoPlannerRules() { final String sql = "select /*+ use_hash_join(r, s), use_hash_join(emp, dept) */\n" + "ename, job, sal, dept.name\n" + "from emp join dept on emp.deptno = dept.deptno"; RelOptPlanner planner = new VolcanoPlanner(); planner.addRelTraitDef(ConventionTraitDef.INSTANCE); Tester tester1 = tester.withDecorrelation(true) .withClusterFactory( relOptCluster -> RelOptCluster.create(planner, relOptCluster.getRexBuilder())); final RelNode rel = tester1.convertSqlToRel(sql).rel; final RelHint hint = RelHint.builder("USE_HASH_JOIN") .inheritPath(0) .hintOption("EMP") .hintOption("DEPT") .build(); // Validate Volcano planner. RuleSet ruleSet = RuleSets.ofList( new MockEnumerableJoinRule(hint), // Rule to validate the hint. FilterProjectTransposeRule.INSTANCE, FilterMergeRule.INSTANCE, ProjectMergeRule.INSTANCE, EnumerableRules.ENUMERABLE_JOIN_RULE, EnumerableRules.ENUMERABLE_PROJECT_RULE, EnumerableRules.ENUMERABLE_FILTER_RULE, EnumerableRules.ENUMERABLE_SORT_RULE, EnumerableRules.ENUMERABLE_LIMIT_RULE, EnumerableRules.ENUMERABLE_TABLE_SCAN_RULE); Program program = Programs.of(ruleSet); RelTraitSet toTraits = rel .getCluster() .traitSet() .replace(EnumerableConvention.INSTANCE); program.run(planner, rel, toTraits, Collections.emptyList(), Collections.emptyList()); }
Example #9
Source File: UnifyingSubstitutionProvider.java From dremio-oss with Apache License 2.0 | 4 votes |
protected HepProgramBuilder getProgramBuilder() { return new HepProgramBuilder() .addRuleInstance(PushFilterPastProjectRule.CALCITE_NO_CHILD_CHECK) .addRuleInstance(ProjectMergeRule.INSTANCE) .addRuleInstance(ProjectRemoveRule.INSTANCE); }
Example #10
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); }