Search in sources :

Example 96 with RelOptCluster

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);
}
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)

Example 97 with RelOptCluster

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);
}
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 98 with RelOptCluster

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);
}
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)

Example 99 with RelOptCluster

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);
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) AbstractRelNode(org.apache.calcite.rel.AbstractRelNode) RelNode(org.apache.calcite.rel.RelNode) Test(org.junit.Test)

Example 100 with RelOptCluster

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);
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) AbstractRelNode(org.apache.calcite.rel.AbstractRelNode) RelNode(org.apache.calcite.rel.RelNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

RelOptCluster (org.apache.calcite.plan.RelOptCluster)117 RelNode (org.apache.calcite.rel.RelNode)63 RelTraitSet (org.apache.calcite.plan.RelTraitSet)36 RexBuilder (org.apache.calcite.rex.RexBuilder)35 RexNode (org.apache.calcite.rex.RexNode)31 ArrayList (java.util.ArrayList)25 RelDataType (org.apache.calcite.rel.type.RelDataType)23 Test (org.junit.Test)21 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)15 List (java.util.List)13 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)13 RelBuilder (org.apache.calcite.tools.RelBuilder)13 RelCollation (org.apache.calcite.rel.RelCollation)12 RelMetadataQuery (org.apache.calcite.rel.metadata.RelMetadataQuery)11 RelOptTable (org.apache.calcite.plan.RelOptTable)10 ImmutableList (com.google.common.collect.ImmutableList)9 HashMap (java.util.HashMap)9 RelOptPlanner (org.apache.calcite.plan.RelOptPlanner)9 Join (org.apache.calcite.rel.core.Join)9 LogicalJoin (org.apache.calcite.rel.logical.LogicalJoin)9