Search in sources :

Example 6 with HiveRulesRegistry

use of org.apache.hadoop.hive.ql.optimizer.calcite.rules.HiveRulesRegistry in project hive by apache.

the class TestCBORuleFiredOnlyOnce method testRuleFiredOnlyOnce.

@Test
public void testRuleFiredOnlyOnce() {
    HiveConf conf = new HiveConf();
    // Create HepPlanner
    HepProgramBuilder programBuilder = new HepProgramBuilder();
    programBuilder.addMatchOrder(HepMatchOrder.TOP_DOWN);
    programBuilder = programBuilder.addRuleCollection(ImmutableList.<RelOptRule>of(DummyRule.INSTANCE));
    // Create rules registry to not trigger a rule more than once
    HiveRulesRegistry registry = new HiveRulesRegistry();
    HivePlannerContext context = new HivePlannerContext(null, registry, null, null, null, null);
    HepPlanner planner = new HepPlanner(programBuilder.build(), context);
    // Cluster
    RexBuilder rexBuilder = new RexBuilder(new JavaTypeFactoryImpl());
    RelOptCluster cluster = RelOptCluster.create(planner, rexBuilder);
    // Create MD provider
    HiveDefaultRelMetadataProvider mdProvider = new HiveDefaultRelMetadataProvider(conf, null);
    List<RelMetadataProvider> list = Lists.newArrayList();
    list.add(mdProvider.getMetadataProvider());
    planner.registerMetadataProviders(list);
    RelMetadataProvider chainedProvider = ChainedRelMetadataProvider.of(list);
    final RelNode node = new DummyNode(cluster, cluster.traitSet());
    node.getCluster().setMetadataProvider(new CachingRelMetadataProvider(chainedProvider, planner));
    planner.setRoot(node);
    planner.findBestExp();
    // Matches 2 times: one time the original node, one time the new node created by the rule
    assertEquals(2, DummyRule.INSTANCE.numberMatches);
    // It is fired only once: on the original node
    assertEquals(1, DummyRule.INSTANCE.numberOnMatch);
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) CachingRelMetadataProvider(org.apache.calcite.rel.metadata.CachingRelMetadataProvider) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) HepPlanner(org.apache.calcite.plan.hep.HepPlanner) RelOptRule(org.apache.calcite.plan.RelOptRule) HiveRulesRegistry(org.apache.hadoop.hive.ql.optimizer.calcite.rules.HiveRulesRegistry) AbstractRelNode(org.apache.calcite.rel.AbstractRelNode) RelNode(org.apache.calcite.rel.RelNode) JavaTypeFactoryImpl(org.apache.calcite.jdbc.JavaTypeFactoryImpl) RexBuilder(org.apache.calcite.rex.RexBuilder) ChainedRelMetadataProvider(org.apache.calcite.rel.metadata.ChainedRelMetadataProvider) CachingRelMetadataProvider(org.apache.calcite.rel.metadata.CachingRelMetadataProvider) RelMetadataProvider(org.apache.calcite.rel.metadata.RelMetadataProvider) HiveConf(org.apache.hadoop.hive.conf.HiveConf) Test(org.junit.Test)

Aggregations

HiveRulesRegistry (org.apache.hadoop.hive.ql.optimizer.calcite.rules.HiveRulesRegistry)6 CalciteSemanticException (org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException)3 Properties (java.util.Properties)2 CalciteConnectionConfig (org.apache.calcite.config.CalciteConnectionConfig)2 CalciteConnectionConfigImpl (org.apache.calcite.config.CalciteConnectionConfigImpl)2 InvalidRelException (org.apache.calcite.rel.InvalidRelException)2 QueryProperties (org.apache.hadoop.hive.ql.QueryProperties)2 HiveConfPlannerContext (org.apache.hadoop.hive.ql.optimizer.calcite.HiveConfPlannerContext)2 HivePlannerContext (org.apache.hadoop.hive.ql.optimizer.calcite.HivePlannerContext)2 HiveAlgorithmsConf (org.apache.hadoop.hive.ql.optimizer.calcite.cost.HiveAlgorithmsConf)2 JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)1 RelOptCluster (org.apache.calcite.plan.RelOptCluster)1 RelOptPlanner (org.apache.calcite.plan.RelOptPlanner)1 RelOptRule (org.apache.calcite.plan.RelOptRule)1 HepPlanner (org.apache.calcite.plan.hep.HepPlanner)1 HepProgramBuilder (org.apache.calcite.plan.hep.HepProgramBuilder)1 AbstractRelNode (org.apache.calcite.rel.AbstractRelNode)1 RelNode (org.apache.calcite.rel.RelNode)1 JoinInfo (org.apache.calcite.rel.core.JoinInfo)1 CachingRelMetadataProvider (org.apache.calcite.rel.metadata.CachingRelMetadataProvider)1