Search in sources :

Example 1 with PhysLeafRel

use of org.apache.calcite.plan.volcano.PlannerTests.PhysLeafRel in project calcite by apache.

the class VolcanoPlannerTest method testRemoveSingleReformed.

/**
 * Previously, this didn't work because ReformedRemoveSingleRule uses a
 * pattern which spans calling conventions.
 */
// broken, because ReformedSingleRule matches child traits strictly
@Ignore
@Test
public void testRemoveSingleReformed() {
    VolcanoPlanner planner = new VolcanoPlanner();
    planner.ambitious = true;
    planner.addRelTraitDef(ConventionTraitDef.INSTANCE);
    planner.addRule(new PhysLeafRule());
    planner.addRule(new ReformedRemoveSingleRule());
    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);
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) RelNode(org.apache.calcite.rel.RelNode) PhysLeafRule(org.apache.calcite.plan.volcano.PlannerTests.PhysLeafRule) NoneSingleRel(org.apache.calcite.plan.volcano.PlannerTests.NoneSingleRel) NoneLeafRel(org.apache.calcite.plan.volcano.PlannerTests.NoneLeafRel) PhysLeafRel(org.apache.calcite.plan.volcano.PlannerTests.PhysLeafRel) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with PhysLeafRel

use of org.apache.calcite.plan.volcano.PlannerTests.PhysLeafRel in project calcite by apache.

the class VolcanoPlannerTest method testListener.

/**
 * Tests whether planner correctly notifies listeners of events.
 */
@Ignore
@Test
public void testListener() {
    TestListener listener = new TestListener();
    VolcanoPlanner planner = new VolcanoPlanner();
    planner.addListener(listener);
    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);
    List<RelOptListener.RelEvent> eventList = listener.getEventList();
    // add node
    checkEvent(eventList, 0, RelOptListener.RelEquivalenceEvent.class, leafRel, null);
    // internal subset
    checkEvent(eventList, 1, RelOptListener.RelEquivalenceEvent.class, null, null);
    // before rule
    checkEvent(eventList, 2, RelOptListener.RuleAttemptedEvent.class, leafRel, PhysLeafRule.class);
    // before rule
    checkEvent(eventList, 3, RelOptListener.RuleProductionEvent.class, result, PhysLeafRule.class);
    // result of rule
    checkEvent(eventList, 4, RelOptListener.RelEquivalenceEvent.class, result, null);
    // after rule
    checkEvent(eventList, 5, RelOptListener.RuleProductionEvent.class, result, PhysLeafRule.class);
    // after rule
    checkEvent(eventList, 6, RelOptListener.RuleAttemptedEvent.class, leafRel, PhysLeafRule.class);
    // choose plan
    checkEvent(eventList, 7, RelOptListener.RelChosenEvent.class, result, null);
    // finish choosing plan
    checkEvent(eventList, 8, RelOptListener.RelChosenEvent.class, null, null);
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) RelOptListener(org.apache.calcite.plan.RelOptListener) RelNode(org.apache.calcite.rel.RelNode) PhysLeafRule(org.apache.calcite.plan.volcano.PlannerTests.PhysLeafRule) NoneLeafRel(org.apache.calcite.plan.volcano.PlannerTests.NoneLeafRel) PhysLeafRel(org.apache.calcite.plan.volcano.PlannerTests.PhysLeafRel) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with PhysLeafRel

use of org.apache.calcite.plan.volcano.PlannerTests.PhysLeafRel in project calcite by apache.

the class VolcanoPlannerTest method testTransformLeaf.

// ~ Methods ----------------------------------------------------------------
/**
 * 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);
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) RelNode(org.apache.calcite.rel.RelNode) PhysLeafRule(org.apache.calcite.plan.volcano.PlannerTests.PhysLeafRule) NoneLeafRel(org.apache.calcite.plan.volcano.PlannerTests.NoneLeafRel) PhysLeafRel(org.apache.calcite.plan.volcano.PlannerTests.PhysLeafRel) Test(org.junit.Test)

Example 4 with PhysLeafRel

use of org.apache.calcite.plan.volcano.PlannerTests.PhysLeafRel 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);
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) GoodSingleRule(org.apache.calcite.plan.volcano.PlannerTests.GoodSingleRule) RelNode(org.apache.calcite.rel.RelNode) PhysLeafRule(org.apache.calcite.plan.volcano.PlannerTests.PhysLeafRule) NoneSingleRel(org.apache.calcite.plan.volcano.PlannerTests.NoneSingleRel) NoneLeafRel(org.apache.calcite.plan.volcano.PlannerTests.NoneLeafRel) PhysLeafRel(org.apache.calcite.plan.volcano.PlannerTests.PhysLeafRel) Test(org.junit.Test)

Example 5 with PhysLeafRel

use of org.apache.calcite.plan.volcano.PlannerTests.PhysLeafRel 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);
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) ConverterRule(org.apache.calcite.rel.convert.ConverterRule) RelBuilder(org.apache.calcite.tools.RelBuilder) GoodSingleRule(org.apache.calcite.plan.volcano.PlannerTests.GoodSingleRule) RelNode(org.apache.calcite.rel.RelNode) PhysLeafRule(org.apache.calcite.plan.volcano.PlannerTests.PhysLeafRule) NoneSingleRel(org.apache.calcite.plan.volcano.PlannerTests.NoneSingleRel) PhysLeafRel(org.apache.calcite.plan.volcano.PlannerTests.PhysLeafRel)

Aggregations

RelOptCluster (org.apache.calcite.plan.RelOptCluster)5 PhysLeafRel (org.apache.calcite.plan.volcano.PlannerTests.PhysLeafRel)5 PhysLeafRule (org.apache.calcite.plan.volcano.PlannerTests.PhysLeafRule)5 RelNode (org.apache.calcite.rel.RelNode)5 NoneLeafRel (org.apache.calcite.plan.volcano.PlannerTests.NoneLeafRel)4 Test (org.junit.Test)4 NoneSingleRel (org.apache.calcite.plan.volcano.PlannerTests.NoneSingleRel)3 GoodSingleRule (org.apache.calcite.plan.volcano.PlannerTests.GoodSingleRule)2 Ignore (org.junit.Ignore)2 RelOptListener (org.apache.calcite.plan.RelOptListener)1 ConverterRule (org.apache.calcite.rel.convert.ConverterRule)1 RelBuilder (org.apache.calcite.tools.RelBuilder)1