use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptCluster in project calcite by apache.
the class ComboRuleTest method testCombo.
@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);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptCluster in project calcite by apache.
the class TraitConversionTest method testTraitConversion.
@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));
}
use of org.apache.beam.vendor.calcite.v1_28_0.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.beam.vendor.calcite.v1_28_0.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.beam.vendor.calcite.v1_28_0.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);
}
Aggregations