Ejemplo n.º 1
0
  /** Appy Join Order Optimizations using Hep Planner. */
  private RelNode getLoptJoinOrderTree(
      RelNode root,
      Class<? extends Join> joinClass,
      RelFactories.JoinFactory joinFactory,
      RelFactories.FilterFactory filterFactory,
      RelFactories.ProjectFactory projectFactory) {
    final HepProgramBuilder hepPgmBldr =
        new HepProgramBuilder()
            .addMatchOrder(HepMatchOrder.BOTTOM_UP)
            .addRuleInstance(new JoinToMultiJoinRule(joinClass))
            .addRuleInstance(new LoptOptimizeJoinRule(joinFactory, projectFactory, filterFactory))
            .addRuleInstance(ProjectRemoveRule.INSTANCE);
    // .addRuleInstance(new ProjectMergeRule(true, projectFactory));

    // .addRuleInstance(DrillMergeProjectRule.getInstance(true, projectFactory,
    // this.context.getFunctionRegistry()));

    final HepProgram hepPgm = hepPgmBldr.build();
    final HepPlanner hepPlanner = new HepPlanner(hepPgm);

    final List<RelMetadataProvider> list = Lists.newArrayList();
    list.add(DrillDefaultRelMetadataProvider.INSTANCE);
    hepPlanner.registerMetadataProviders(list);
    final RelMetadataProvider cachingMetaDataProvider =
        new CachingRelMetadataProvider(ChainedRelMetadataProvider.of(list), hepPlanner);

    // Modify RelMetaProvider for every RelNode in the SQL operator Rel tree.
    root.accept(new MetaDataProviderModifier(cachingMetaDataProvider));

    hepPlanner.setRoot(root);

    RelNode calciteOptimizedPlan = hepPlanner.findBestExp();

    return calciteOptimizedPlan;
  }
Ejemplo n.º 2
0
 public RelMetadataProvider getMetadataProvider() {
   return ChainedRelMetadataProvider.of(
       ImmutableList.of(
           ReflectiveRelMetadataProvider.reflectiveSource(
               this, BuiltInMethod.NON_CUMULATIVE_COST.method),
           RelMdPercentageOriginalRows.SOURCE));
 }
Ejemplo n.º 3
0
  private RelNode convertToRel(SqlNode node) throws RelConversionException {
    final RelNode convertedNode = planner.convert(node);

    final RelMetadataProvider provider = convertedNode.getCluster().getMetadataProvider();

    // Register RelMetadataProvider with HepPlanner.
    final List<RelMetadataProvider> list = Lists.newArrayList(provider);
    hepPlanner.registerMetadataProviders(list);
    final RelMetadataProvider cachingMetaDataProvider =
        new CachingRelMetadataProvider(ChainedRelMetadataProvider.of(list), hepPlanner);
    convertedNode.accept(new MetaDataProviderModifier(cachingMetaDataProvider));

    // HepPlanner is specifically used for Window Function planning only.
    hepPlanner.setRoot(convertedNode);
    RelNode rel = hepPlanner.findBestExp();

    rel.accept(new MetaDataProviderModifier(provider));
    return rel;
  }