Search in sources :

Example 1 with NoneSingleRel

use of org.apache.calcite.plan.volcano.PlannerTests.NoneSingleRel 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 NoneSingleRel

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

the class VolcanoPlannerTest method testTransformSingleReformed.

/**
 * Tests transformation of a single+leaf from NONE to PHYS. In the past,
 * this one didn't work due to the definition of ReformedSingleRule.
 */
// broken, because ReformedSingleRule matches child traits strictly
@Ignore
@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);
}
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) PhysSingleRel(org.apache.calcite.plan.volcano.PlannerTests.PhysSingleRel) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with NoneSingleRel

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

the class VolcanoPlannerTest method testSubsetRule.

/**
 * Tests a rule that is fired once per subset (whereas most rules are fired
 * once per rel in a set or rel in a subset)
 */
@Test
public void testSubsetRule() {
    VolcanoPlanner planner = new VolcanoPlanner();
    planner.addRelTraitDef(ConventionTraitDef.INSTANCE);
    planner.addRule(new PhysLeafRule());
    planner.addRule(new GoodSingleRule());
    final List<String> buf = new ArrayList<>();
    planner.addRule(new SubsetRule(buf));
    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);
    assertThat(sort(buf), equalTo(sort("NoneSingleRel:Subset#0.NONE", "PhysSingleRel:Subset#0.NONE", "PhysSingleRel:Subset#0.PHYS")));
}
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) ArrayList(java.util.ArrayList) NoneLeafRel(org.apache.calcite.plan.volcano.PlannerTests.NoneLeafRel) PhysSingleRel(org.apache.calcite.plan.volcano.PlannerTests.PhysSingleRel) Test(org.junit.Test)

Example 4 with NoneSingleRel

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

Example 5 with NoneSingleRel

use of org.apache.calcite.plan.volcano.PlannerTests.NoneSingleRel 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);
}
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) PhysSingleRel(org.apache.calcite.plan.volcano.PlannerTests.PhysSingleRel) Test(org.junit.Test)

Aggregations

RelOptCluster (org.apache.calcite.plan.RelOptCluster)7 NoneSingleRel (org.apache.calcite.plan.volcano.PlannerTests.NoneSingleRel)7 RelNode (org.apache.calcite.rel.RelNode)7 NoneLeafRel (org.apache.calcite.plan.volcano.PlannerTests.NoneLeafRel)6 PhysLeafRule (org.apache.calcite.plan.volcano.PlannerTests.PhysLeafRule)6 Test (org.junit.Test)6 GoodSingleRule (org.apache.calcite.plan.volcano.PlannerTests.GoodSingleRule)5 PhysLeafRel (org.apache.calcite.plan.volcano.PlannerTests.PhysLeafRel)3 PhysSingleRel (org.apache.calcite.plan.volcano.PlannerTests.PhysSingleRel)3 Ignore (org.junit.Ignore)2 ArrayList (java.util.ArrayList)1 ConverterRule (org.apache.calcite.rel.convert.ConverterRule)1 RelBuilder (org.apache.calcite.tools.RelBuilder)1