Ejemplo n.º 1
0
  private void parseAndRunLogicalPlan(final String json) throws ExecutionSetupException {
    LogicalPlan logicalPlan;
    try {
      logicalPlan = drillbitContext.getPlanReader().readLogicalPlan(json);
    } catch (final IOException e) {
      throw new ForemanException("Failure parsing logical plan.", e);
    }

    if (logicalPlan.getProperties().resultMode == ResultMode.LOGICAL) {
      throw new ForemanException(
          "Failure running plan.  You requested a result mode of LOGICAL and submitted a logical plan.  In this case you're output mode must be PHYSICAL or EXEC.");
    }

    log(logicalPlan);

    final PhysicalPlan physicalPlan = convert(logicalPlan);

    if (logicalPlan.getProperties().resultMode == ResultMode.PHYSICAL) {
      returnPhysical(physicalPlan);
      return;
    }

    log(physicalPlan);
    runPhysicalPlan(physicalPlan);
  }
Ejemplo n.º 2
0
  private void parseAndRunLogicalPlan(String json) {

    try {
      LogicalPlan logicalPlan = context.getPlanReader().readLogicalPlan(json);

      if (logicalPlan.getProperties().resultMode == ResultMode.LOGICAL) {
        fail(
            "Failure running plan.  You requested a result mode of LOGICAL and submitted a logical plan.  In this case you're output mode must be PHYSICAL or EXEC.",
            new Exception());
      }
      if (logger.isDebugEnabled())
        logger.debug("Logical {}", logicalPlan.unparse(context.getConfig()));
      PhysicalPlan physicalPlan = convert(logicalPlan);

      if (logicalPlan.getProperties().resultMode == ResultMode.PHYSICAL) {
        returnPhysical(physicalPlan);
        return;
      }

      if (logger.isDebugEnabled())
        logger.debug(
            "Physical {}", context.getConfig().getMapper().writeValueAsString(physicalPlan));
      runPhysicalPlan(physicalPlan);
    } catch (IOException e) {
      fail("Failure while parsing logical plan.", e);
    } catch (OptimizerException e) {
      fail("Failure while converting logical plan to physical plan.", e);
    }
  }
Ejemplo n.º 3
0
 private PhysicalPlan convert(final LogicalPlan plan) throws OptimizerException {
   if (logger.isDebugEnabled()) {
     logger.debug("Converting logical plan {}.", plan.toJsonStringSafe(queryContext.getConfig()));
   }
   return new BasicOptimizer(queryContext, initiatingClient)
       .optimize(new BasicOptimizer.BasicOptimizationContext(queryContext), plan);
 }
Ejemplo n.º 4
0
  @Override
  public PhysicalPlan optimize(OptimizationContext context, LogicalPlan plan)
      throws OptimizerException {
    Object obj = new Object();
    Collection<SinkOperator> roots = plan.getGraph().getRoots();
    List<PhysicalOperator> physOps = new ArrayList<PhysicalOperator>(roots.size());
    LogicalConverter converter = new LogicalConverter(plan);
    for (SinkOperator op : roots) {
      PhysicalOperator pop = op.accept(converter, obj);
      physOps.add(pop);
    }

    PlanProperties props =
        PlanProperties.builder()
            .type(PlanProperties.PlanType.APACHE_DRILL_PHYSICAL)
            .version(plan.getProperties().version)
            .generator(plan.getProperties().generator)
            .build();
    PhysicalPlan p = new PhysicalPlan(props, physOps);
    return p;
    // return new PhysicalPlan(props, physOps);
  }
Ejemplo n.º 5
0
 @Override
 public PhysicalOperator visitScan(Scan scan, Object obj) throws OptimizerException {
   StorageEngineConfig config = logicalPlan.getStorageEngineConfig(scan.getStorageEngine());
   if (config == null)
     throw new OptimizerException(
         String.format(
             "Logical plan referenced the storage engine config %s but the logical plan didn't have that available as a config.",
             scan.getStorageEngine()));
   StorageEngine engine;
   try {
     engine = context.getStorageEngine(config);
     return engine.getPhysicalScan(scan);
   } catch (IOException | ExecutionSetupException e) {
     throw new OptimizerException("Failure while attempting to retrieve storage engine.", e);
   }
 }
Ejemplo n.º 6
0
 private void log(final LogicalPlan plan) {
   if (logger.isDebugEnabled()) {
     logger.debug("Logical {}", plan.unparse(queryContext.getConfig()));
   }
 }
Ejemplo n.º 7
0
 private PhysicalPlan convert(LogicalPlan plan) throws OptimizerException {
   if (logger.isDebugEnabled())
     logger.debug("Converting logical plan {}.", plan.toJsonStringSafe(context.getConfig()));
   return new BasicOptimizer(DrillConfig.create(), context)
       .optimize(new BasicOptimizer.BasicOptimizationContext(), plan);
 }