drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinfengni <...@git.apache.org>
Subject [GitHub] drill pull request: DRILL-4465: Simplify Calcite parsing & plannin...
Date Thu, 03 Mar 2016 00:23:45 GMT
Github user jinfengni commented on a diff in the pull request:

    https://github.com/apache/drill/pull/401#discussion_r54817380
  
    --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DefaultSqlHandler.java
---
    @@ -273,12 +282,90 @@ public RelNode visit(RelNode other) {
     
       }
     
    +  /**
    +   * Transform RelNode to a new RelNode without changing any traits. Also will log the
outcome.
    +   *
    +   * @param plannerType
    +   *          The type of Planner to use.
    +   * @param phase
    +   *          The transformation phase we're running.
    +   * @param input
    +   *          The origianl RelNode
    +   * @return The transformed relnode.
    +   */
    +  private RelNode transform(PlannerType plannerType, PlannerPhase phase, RelNode input)
{
    +    return transform(plannerType, phase, input, input.getTraitSet());
    +  }
    +
    +  /**
    +   * Transform RelNode to a new RelNode, targeting the provided set of traits. Also will
log the outcome.
    +   *
    +   * @param plannerType
    +   *          The type of Planner to use.
    +   * @param phase
    +   *          The transformation phase we're running.
    +   * @param input
    +   *          The origianl RelNode
    +   * @param targetTraits
    +   *          The traits we are targeting for output.
    +   * @return The transformed relnode.
    +   */
    +  protected RelNode transform(PlannerType plannerType, PlannerPhase phase, RelNode input,
RelTraitSet targetTraits) {
    +    final Stopwatch watch = Stopwatch.createStarted();
    +    final RuleSet rules = config.getRules(phase);
    +    final RelTraitSet toTraits = targetTraits.simplify();
    +
    +    final RelNode output;
    +    switch (plannerType) {
    +    case HEP_BOTTOM_UP:
    +    case HEP: {
    +      final HepProgramBuilder hepPgmBldr = new HepProgramBuilder();
    +      if (plannerType == PlannerType.HEP_BOTTOM_UP) {
    +        hepPgmBldr.addMatchOrder(HepMatchOrder.BOTTOM_UP);
    +      }
    +      for (RelOptRule rule : rules) {
    +        hepPgmBldr.addRuleInstance(rule);
    +      }
    +
    +      final HepPlanner planner = new HepPlanner(hepPgmBldr.build(), context.getPlannerSettings());
    +
    +      final List<RelMetadataProvider> list = Lists.newArrayList();
    +      list.add(DrillDefaultRelMetadataProvider.INSTANCE);
    +      planner.registerMetadataProviders(list);
    +      final RelMetadataProvider cachingMetaDataProvider = new CachingRelMetadataProvider(
    +          ChainedRelMetadataProvider.of(list), planner);
    +
    +      // Modify RelMetaProvider for every RelNode in the SQL operator Rel tree.
    +      input.accept(new MetaDataProviderModifier(cachingMetaDataProvider));
    +      planner.setRoot(input);
    +      if (!input.getTraitSet().equals(targetTraits)) {
    +        planner.changeTraits(input, toTraits);
    +      }
    +      output = planner.findBestExp();
    +      break;
    +    }
    +    case VOLCANO:
    +    default: {
    +      // as weird as it seems, the cluster's only planner is the volcano planner.
    +      final RelOptPlanner planner = input.getCluster().getPlanner();
    --- End diff --
    
    Probably better to add check if the planner is instance of Volcano. If the RelNode tree
comes from DrillSqlParser.toRel() call, then it's always volcano. But what if it could come
from somewhere else and it's not volcano in RelCluster.getPlanner() ? 



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message