calciteOptimizedPlan = planner.findBestExp();
basePlan = planner.findBestExp();
public RelNode run(RelOptPlanner planner, RelNode rel, RelTraitSet requiredOutputTraits, List<RelOptMaterialization> materializations, List<RelOptLattice> lattices) { planner.clear(); for (RelOptRule rule : ruleSet) { planner.addRule(rule); } for (RelOptMaterialization materialization : materializations) { planner.addMaterialization(materialization); } for (RelOptLattice lattice : lattices) { planner.addLattice(lattice); } if (!rel.getTraitSet().equals(requiredOutputTraits)) { rel = planner.changeTraits(rel, requiredOutputTraits); } planner.setRoot(rel); return planner.findBestExp(); } }
private void checkCancelFlag(RelOptPlanner planner) { expectedException.expect(UserException.class); RelOptCluster cluster = RelOptCluster.create(planner, new RexBuilder(SqlTypeFactoryImpl.INSTANCE)); RelNode root = new NoneRel(cluster); planner.setRoot(root); planner.findBestExp(); }
public RelNode run(RelOptPlanner planner, RelNode rel, RelTraitSet requiredOutputTraits, List<RelOptMaterialization> materializations, List<RelOptLattice> lattices) { planner.clear(); for (RelOptRule rule : ruleSet) { planner.addRule(rule); } for (RelOptMaterialization materialization : materializations) { planner.addMaterialization(materialization); } for (RelOptLattice lattice : lattices) { planner.addLattice(lattice); } if (!rel.getTraitSet().equals(requiredOutputTraits)) { rel = planner.changeTraits(rel, requiredOutputTraits); } planner.setRoot(rel); return planner.findBestExp(); } }
public RelNode run(RelOptPlanner planner, RelNode rel, RelTraitSet requiredOutputTraits, List<RelOptMaterialization> materializations, List<RelOptLattice> lattices) { planner.clear(); for (RelOptRule rule : ruleSet) { planner.addRule(rule); } for (RelOptMaterialization materialization : materializations) { planner.addMaterialization(materialization); } for (RelOptLattice lattice : lattices) { planner.addLattice(lattice); } if (!rel.getTraitSet().equals(requiredOutputTraits)) { rel = planner.changeTraits(rel, requiredOutputTraits); } planner.setRoot(rel); return planner.findBestExp(); } }
public RelNode run(RelOptPlanner planner, RelNode rel, RelTraitSet requiredOutputTraits, List<RelOptMaterialization> materializations, List<RelOptLattice> lattices) { planner.setRoot(rel); for (RelOptMaterialization materialization : materializations) { planner.addMaterialization(materialization); } for (RelOptLattice lattice : lattices) { planner.addLattice(lattice); } final RelNode rootRel2 = rel.getTraitSet().equals(requiredOutputTraits) ? rel : planner.changeTraits(rel, requiredOutputTraits); assert rootRel2 != null; planner.setRoot(rootRel2); final RelOptPlanner planner2 = planner.chooseDelegate(); final RelNode rootRel3 = planner2.findBestExp(); assert rootRel3 != null : "could not implement exp"; return rootRel3; } };
/** * Tests transformation of a leaf from NONE to PHYS. */ @Test public void testTransformLeaf() { VolcanoPlanner planner = new VolcanoPlanner(); planner.addRelTraitDef(ConventionTraitDef.INSTANCE); planner.addRule(new PhysLeafRule()); RelOptCluster cluster = newCluster(planner); NoneLeafRel leafRel = new NoneLeafRel( cluster, "a"); RelNode convertedRel = planner.changeTraits( leafRel, cluster.traitSetOf(PHYS_CALLING_CONVENTION)); planner.setRoot(convertedRel); RelNode result = planner.chooseDelegate().findBestExp(); assertTrue(result instanceof PhysLeafRel); }
/** * Tests transformation of a leaf from NONE to PHYS. */ @Test public void testTransformLeaf() { VolcanoPlanner planner = new VolcanoPlanner(); planner.addRelTraitDef(ConventionTraitDef.INSTANCE); planner.addRule(new PhysLeafRule()); RelOptCluster cluster = newCluster(planner); NoneLeafRel leafRel = new NoneLeafRel( cluster, "a"); RelNode convertedRel = planner.changeTraits( leafRel, cluster.traitSetOf(PHYS_CALLING_CONVENTION)); planner.setRoot(convertedRel); RelNode result = planner.chooseDelegate().findBestExp(); assertTrue(result instanceof PhysLeafRel); }
/** * Tests transformation of a single+leaf from NONE to PHYS. */ @Test public void testTransformSingleGood() { VolcanoPlanner planner = new VolcanoPlanner(); planner.addRelTraitDef(ConventionTraitDef.INSTANCE); planner.addRule(new PhysLeafRule()); planner.addRule(new GoodSingleRule()); RelOptCluster cluster = newCluster(planner); NoneLeafRel leafRel = new NoneLeafRel( cluster, "a"); NoneSingleRel singleRel = new NoneSingleRel( cluster, leafRel); RelNode convertedRel = planner.changeTraits( singleRel, cluster.traitSetOf(PHYS_CALLING_CONVENTION)); planner.setRoot(convertedRel); RelNode result = planner.chooseDelegate().findBestExp(); assertTrue(result instanceof PhysSingleRel); }
/** * Tests transformation of a single+leaf from NONE to PHYS. */ @Test public void testTransformSingleGood() { VolcanoPlanner planner = new VolcanoPlanner(); planner.addRelTraitDef(ConventionTraitDef.INSTANCE); planner.addRule(new PhysLeafRule()); planner.addRule(new GoodSingleRule()); RelOptCluster cluster = newCluster(planner); NoneLeafRel leafRel = new NoneLeafRel( cluster, "a"); NoneSingleRel singleRel = new NoneSingleRel( cluster, leafRel); RelNode convertedRel = planner.changeTraits( singleRel, cluster.traitSetOf(PHYS_CALLING_CONVENTION)); planner.setRoot(convertedRel); RelNode result = planner.chooseDelegate().findBestExp(); assertTrue(result instanceof PhysSingleRel); }
@Test public void testCombo() { VolcanoPlanner planner = new VolcanoPlanner(); planner.addRelTraitDef(ConventionTraitDef.INSTANCE); planner.addRule(new ComboRule()); planner.addRule(new AddIntermediateNodeRule()); planner.addRule(new GoodSingleRule()); RelOptCluster cluster = newCluster(planner); NoneLeafRel leafRel = new NoneLeafRel(cluster, "a"); NoneSingleRel singleRel = new NoneSingleRel(cluster, leafRel); NoneSingleRel singleRel2 = new NoneSingleRel(cluster, singleRel); RelNode convertedRel = planner.changeTraits(singleRel2, cluster.traitSetOf(PHYS_CALLING_CONVENTION)); planner.setRoot(convertedRel); RelNode result = planner.chooseDelegate().findBestExp(); assertTrue(result instanceof IntermediateNode); }
@Test public void testCombo() { VolcanoPlanner planner = new VolcanoPlanner(); planner.addRelTraitDef(ConventionTraitDef.INSTANCE); planner.addRule(new ComboRule()); planner.addRule(new AddIntermediateNodeRule()); planner.addRule(new GoodSingleRule()); RelOptCluster cluster = newCluster(planner); NoneLeafRel leafRel = new NoneLeafRel(cluster, "a"); NoneSingleRel singleRel = new NoneSingleRel(cluster, leafRel); NoneSingleRel singleRel2 = new NoneSingleRel(cluster, singleRel); RelNode convertedRel = planner.changeTraits(singleRel2, cluster.traitSetOf(PHYS_CALLING_CONVENTION)); planner.setRoot(convertedRel); RelNode result = planner.chooseDelegate().findBestExp(); assertTrue(result instanceof IntermediateNode); }
/** * Tests transformation of a single+leaf from NONE to PHYS. In the past, * this one didn't work due to the definition of ReformedSingleRule. */ @Ignore // broken, because ReformedSingleRule matches child traits strictly @Test public void testTransformSingleReformed() { VolcanoPlanner planner = new VolcanoPlanner(); planner.addRelTraitDef(ConventionTraitDef.INSTANCE); planner.addRule(new PhysLeafRule()); planner.addRule(new ReformedSingleRule()); RelOptCluster cluster = newCluster(planner); NoneLeafRel leafRel = new NoneLeafRel( cluster, "a"); NoneSingleRel singleRel = new NoneSingleRel( cluster, leafRel); RelNode convertedRel = planner.changeTraits( singleRel, cluster.traitSetOf(PHYS_CALLING_CONVENTION)); planner.setRoot(convertedRel); RelNode result = planner.chooseDelegate().findBestExp(); assertTrue(result instanceof PhysSingleRel); }
/** * Tests transformation of a single+leaf from NONE to PHYS. In the past, * this one didn't work due to the definition of ReformedSingleRule. */ @Ignore // broken, because ReformedSingleRule matches child traits strictly @Test public void testTransformSingleReformed() { VolcanoPlanner planner = new VolcanoPlanner(); planner.addRelTraitDef(ConventionTraitDef.INSTANCE); planner.addRule(new PhysLeafRule()); planner.addRule(new ReformedSingleRule()); RelOptCluster cluster = newCluster(planner); NoneLeafRel leafRel = new NoneLeafRel( cluster, "a"); NoneSingleRel singleRel = new NoneSingleRel( cluster, leafRel); RelNode convertedRel = planner.changeTraits( singleRel, cluster.traitSetOf(PHYS_CALLING_CONVENTION)); planner.setRoot(convertedRel); RelNode result = planner.chooseDelegate().findBestExp(); assertTrue(result instanceof PhysSingleRel); }
@Test public void testRuleMatchAfterConversion() { VolcanoPlanner planner = new VolcanoPlanner(); planner.addRelTraitDef(ConventionTraitDef.INSTANCE); planner.addRelTraitDef(ALT_TRAIT_DEF); planner.addRule(new PhysToIteratorConverterRule()); planner.addRule(new PhysLeafRule()); planner.addRule(new IterSingleRule()); planner.addRule(new IterSinglePhysMergeRule()); RelOptCluster cluster = newCluster(planner); NoneLeafRel noneLeafRel = RelOptUtil.addTrait( new NoneLeafRel(cluster, "noneLeafRel"), ALT_TRAIT); NoneSingleRel noneRel = RelOptUtil.addTrait( new NoneSingleRel(cluster, noneLeafRel), ALT_EMPTY_TRAIT); RelNode convertedRel = planner.changeTraits(noneRel, cluster.traitSetOf(EnumerableConvention.INSTANCE) .replace(ALT_EMPTY_TRAIT)); planner.setRoot(convertedRel); RelNode result = planner.chooseDelegate().findBestExp(); assertTrue(result instanceof IterMergedRel); }
@Test public void testRuleMatchAfterConversion() { VolcanoPlanner planner = new VolcanoPlanner(); planner.addRelTraitDef(ConventionTraitDef.INSTANCE); planner.addRelTraitDef(ALT_TRAIT_DEF); planner.addRule(new PhysToIteratorConverterRule()); planner.addRule(new PhysLeafRule()); planner.addRule(new IterSingleRule()); planner.addRule(new IterSinglePhysMergeRule()); RelOptCluster cluster = newCluster(planner); NoneLeafRel noneLeafRel = RelOptUtil.addTrait( new NoneLeafRel(cluster, "noneLeafRel"), ALT_TRAIT); NoneSingleRel noneRel = RelOptUtil.addTrait( new NoneSingleRel(cluster, noneLeafRel), ALT_EMPTY_TRAIT); RelNode convertedRel = planner.changeTraits(noneRel, cluster.traitSetOf(EnumerableConvention.INSTANCE) .replace(ALT_EMPTY_TRAIT)); planner.setRoot(convertedRel); RelNode result = planner.chooseDelegate().findBestExp(); assertTrue(result instanceof IterMergedRel); }
@Test public void testCollationConversion() { final VolcanoPlanner planner = new VolcanoPlanner(); planner.addRelTraitDef(ConventionTraitDef.INSTANCE); planner.addRelTraitDef(COLLATION_TRAIT_DEF); planner.addRule(new SingleNodeRule()); planner.addRule(new LeafTraitRule()); planner.addRule(ExpandConversionRule.INSTANCE); final RelOptCluster cluster = newCluster(planner); final NoneLeafRel leafRel = new NoneLeafRel(cluster, "a"); final NoneSingleRel singleRel = new NoneSingleRel(cluster, leafRel); final RelNode convertedRel = planner.changeTraits(singleRel, cluster.traitSetOf(PHYS_CALLING_CONVENTION).plus(ROOT_COLLATION)); planner.setRoot(convertedRel); RelNode result = planner.chooseDelegate().findBestExp(); assertTrue(result instanceof RootSingleRel); assertTrue(result.getTraitSet().contains(ROOT_COLLATION)); assertTrue(result.getTraitSet().contains(PHYS_CALLING_CONVENTION)); final RelNode input = result.getInput(0); assertTrue(input instanceof PhysicalSort); assertTrue(result.getTraitSet().contains(ROOT_COLLATION)); assertTrue(input.getTraitSet().contains(PHYS_CALLING_CONVENTION)); final RelNode input2 = input.getInput(0); assertTrue(input2 instanceof LeafRel); assertTrue(input2.getTraitSet().contains(LEAF_COLLATION)); assertTrue(input.getTraitSet().contains(PHYS_CALLING_CONVENTION)); }
@Test public void testTraitConversion() { final VolcanoPlanner planner = new VolcanoPlanner(); planner.addRelTraitDef(ConventionTraitDef.INSTANCE); planner.addRelTraitDef(NEW_TRAIT_DEF_INSTANCE); planner.addRule(new RandomSingleTraitRule()); planner.addRule(new SingleLeafTraitRule()); planner.addRule(ExpandConversionRule.INSTANCE); final RelOptCluster cluster = newCluster(planner); final NoneLeafRel leafRel = new NoneLeafRel(cluster, "a"); final NoneSingleRel singleRel = new NoneSingleRel(cluster, leafRel); final RelNode convertedRel = planner.changeTraits(singleRel, cluster.traitSetOf(PHYS_CALLING_CONVENTION)); planner.setRoot(convertedRel); final RelNode result = planner.chooseDelegate().findBestExp(); assertTrue(result instanceof RandomSingleRel); assertTrue(result.getTraitSet().contains(PHYS_CALLING_CONVENTION)); assertTrue(result.getTraitSet().contains(SIMPLE_DISTRIBUTION_RANDOM)); final RelNode input = result.getInput(0); assertTrue(input instanceof BridgeRel); assertTrue(input.getTraitSet().contains(PHYS_CALLING_CONVENTION)); assertTrue(input.getTraitSet().contains(SIMPLE_DISTRIBUTION_RANDOM)); final RelNode input2 = input.getInput(0); assertTrue(input2 instanceof SingletonLeafRel); assertTrue(input2.getTraitSet().contains(PHYS_CALLING_CONVENTION)); assertTrue(input2.getTraitSet().contains(SIMPLE_DISTRIBUTION_SINGLETON)); }
@Test public void testTraitConversion() { final VolcanoPlanner planner = new VolcanoPlanner(); planner.addRelTraitDef(ConventionTraitDef.INSTANCE); planner.addRelTraitDef(NEW_TRAIT_DEF_INSTANCE); planner.addRule(new RandomSingleTraitRule()); planner.addRule(new SingleLeafTraitRule()); planner.addRule(ExpandConversionRule.INSTANCE); final RelOptCluster cluster = newCluster(planner); final NoneLeafRel leafRel = new NoneLeafRel(cluster, "a"); final NoneSingleRel singleRel = new NoneSingleRel(cluster, leafRel); final RelNode convertedRel = planner.changeTraits(singleRel, cluster.traitSetOf(PHYS_CALLING_CONVENTION)); planner.setRoot(convertedRel); final RelNode result = planner.chooseDelegate().findBestExp(); assertTrue(result instanceof RandomSingleRel); assertTrue(result.getTraitSet().contains(PHYS_CALLING_CONVENTION)); assertTrue(result.getTraitSet().contains(SIMPLE_DISTRIBUTION_RANDOM)); final RelNode input = result.getInput(0); assertTrue(input instanceof BridgeRel); assertTrue(input.getTraitSet().contains(PHYS_CALLING_CONVENTION)); assertTrue(input.getTraitSet().contains(SIMPLE_DISTRIBUTION_RANDOM)); final RelNode input2 = input.getInput(0); assertTrue(input2 instanceof SingletonLeafRel); assertTrue(input2.getTraitSet().contains(PHYS_CALLING_CONVENTION)); assertTrue(input2.getTraitSet().contains(SIMPLE_DISTRIBUTION_SINGLETON)); }