use of org.apache.calcite.plan.RelOptCluster in project calcite by apache.
the class VolcanoPlannerTest method testTransformSingleGood.
/**
* 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);
}
use of org.apache.calcite.plan.RelOptCluster in project calcite by apache.
the class VolcanoPlannerTest method testRemoveSingleGood.
/**
* This always worked (in contrast to testRemoveSingleReformed) because it
* uses a completely-physical pattern (requiring GoodSingleRule to fire
* first).
*/
@Test
public void testRemoveSingleGood() {
VolcanoPlanner planner = new VolcanoPlanner();
planner.ambitious = true;
planner.addRelTraitDef(ConventionTraitDef.INSTANCE);
planner.addRule(new PhysLeafRule());
planner.addRule(new GoodSingleRule());
planner.addRule(new GoodRemoveSingleRule());
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 PhysLeafRel);
PhysLeafRel resultLeaf = (PhysLeafRel) result;
assertEquals("c", resultLeaf.label);
}
use of org.apache.calcite.plan.RelOptCluster in project calcite by apache.
the class VolcanoPlannerTest method removeTrivialProject.
private void removeTrivialProject(boolean useRule) {
VolcanoPlanner planner = new VolcanoPlanner();
planner.ambitious = true;
planner.addRelTraitDef(ConventionTraitDef.INSTANCE);
if (useRule) {
planner.addRule(ProjectRemoveRule.INSTANCE);
}
planner.addRule(new PhysLeafRule());
planner.addRule(new GoodSingleRule());
planner.addRule(new PhysProjectRule());
planner.addRule(new ConverterRule(RelNode.class, PHYS_CALLING_CONVENTION, EnumerableConvention.INSTANCE, "PhysToIteratorRule") {
public RelNode convert(RelNode rel) {
return new PhysToIteratorConverter(rel.getCluster(), rel);
}
});
RelOptCluster cluster = newCluster(planner);
PhysLeafRel leafRel = new PhysLeafRel(cluster, "a");
final RelBuilder relBuilder = RelFactories.LOGICAL_BUILDER.create(leafRel.getCluster(), null);
RelNode projectRel = relBuilder.push(leafRel).project(relBuilder.alias(relBuilder.field(0), "this")).build();
NoneSingleRel singleRel = new NoneSingleRel(cluster, projectRel);
RelNode convertedRel = planner.changeTraits(singleRel, cluster.traitSetOf(EnumerableConvention.INSTANCE));
planner.setRoot(convertedRel);
RelNode result = planner.chooseDelegate().findBestExp();
assertTrue(result instanceof PhysToIteratorConverter);
}
use of org.apache.calcite.plan.RelOptCluster in project calcite by apache.
the class VolcanoPlannerTraitTest method testRuleMatchAfterConversion.
@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);
}
use of org.apache.calcite.plan.RelOptCluster in project calcite by apache.
the class VolcanoPlannerTraitTest method testTraitPropagation.
@Ignore
@Test
public void testTraitPropagation() {
VolcanoPlanner planner = new VolcanoPlanner();
planner.addRelTraitDef(ConventionTraitDef.INSTANCE);
planner.addRelTraitDef(ALT_TRAIT_DEF);
planner.addRule(new PhysToIteratorConverterRule());
planner.addRule(new AltTraitConverterRule(ALT_TRAIT, ALT_TRAIT2, "AltToAlt2ConverterRule"));
planner.addRule(new PhysLeafRule());
planner.addRule(new IterSingleRule2());
RelOptCluster cluster = newCluster(planner);
NoneLeafRel noneLeafRel = RelOptUtil.addTrait(new NoneLeafRel(cluster, "noneLeafRel"), ALT_TRAIT);
NoneSingleRel noneRel = RelOptUtil.addTrait(new NoneSingleRel(cluster, noneLeafRel), ALT_TRAIT2);
RelNode convertedRel = planner.changeTraits(noneRel, cluster.traitSetOf(EnumerableConvention.INSTANCE).replace(ALT_TRAIT2));
planner.setRoot(convertedRel);
RelNode result = planner.chooseDelegate().findBestExp();
assertTrue(result instanceof IterSingleRel);
assertEquals(EnumerableConvention.INSTANCE, result.getTraitSet().getTrait(ConventionTraitDef.INSTANCE));
assertEquals(ALT_TRAIT2, result.getTraitSet().getTrait(ALT_TRAIT_DEF));
RelNode child = result.getInputs().get(0);
assertTrue(child instanceof IterSingleRel);
assertEquals(EnumerableConvention.INSTANCE, child.getTraitSet().getTrait(ConventionTraitDef.INSTANCE));
assertEquals(ALT_TRAIT2, child.getTraitSet().getTrait(ALT_TRAIT_DEF));
child = child.getInputs().get(0);
assertTrue((child instanceof AltTraitConverter) || (child instanceof PhysToIteratorConverter));
child = child.getInputs().get(0);
assertTrue((child instanceof AltTraitConverter) || (child instanceof PhysToIteratorConverter));
child = child.getInputs().get(0);
assertTrue(child instanceof PhysLeafRel);
}
Aggregations