@Override
  public MaterializedResult execute(Session session, @Language("SQL") String sql) {
    lock.readLock().lock();
    try {
      MaterializedOutputFactory outputFactory = new MaterializedOutputFactory();

      TaskContext taskContext = createTaskContext(executor, session);
      List<Driver> drivers = createDrivers(session, sql, outputFactory, taskContext);

      boolean done = false;
      while (!done) {
        boolean processed = false;
        for (Driver driver : drivers) {
          if (!driver.isFinished()) {
            driver.process();
            processed = true;
          }
        }
        done = !processed;
      }

      return outputFactory.getMaterializingOperator().getMaterializedResult();
    } finally {
      lock.readLock().unlock();
    }
  }
  @Override
  protected List<Driver> createDrivers(TaskContext taskContext) {
    if (lookupSourceSupplier == null) {
      OperatorFactory ordersTableScan =
          createTableScanOperator(0, "orders", "orderkey", "totalprice");
      HashBuilderOperatorFactory hashBuilder =
          new HashBuilderOperatorFactory(1, ordersTableScan.getTypes(), Ints.asList(0), 1_500_000);

      DriverContext driverContext = taskContext.addPipelineContext(false, false).addDriverContext();
      Driver driver =
          new DriverFactory(false, false, ordersTableScan, hashBuilder).createDriver(driverContext);
      while (!driver.isFinished()) {
        driver.process();
      }
      lookupSourceSupplier = hashBuilder.getLookupSourceSupplier();
    }

    OperatorFactory lineItemTableScan =
        createTableScanOperator(0, "lineitem", "orderkey", "quantity");

    OperatorFactory joinOperator =
        LookupJoinOperators.innerJoin(
            1, lookupSourceSupplier, lineItemTableScan.getTypes(), Ints.asList(0));

    NullOutputOperatorFactory output = new NullOutputOperatorFactory(2, joinOperator.getTypes());

    DriverFactory driverFactory =
        new DriverFactory(true, true, lineItemTableScan, joinOperator, output);
    DriverContext driverContext = taskContext.addPipelineContext(true, true).addDriverContext();
    Driver driver = driverFactory.createDriver(driverContext);
    return ImmutableList.of(driver);
  }
Exemple #3
0
  public MaterializedResult execute(@Language("SQL") String sql) {
    MaterializedOutputFactory outputFactory = new MaterializedOutputFactory();
    List<Driver> drivers = createDrivers(sql, outputFactory);

    boolean done = false;
    while (!done) {
      boolean processed = false;
      for (Driver driver : drivers) {
        if (!driver.isFinished()) {
          driver.process();
          processed = true;
        }
      }
      done = !processed;
    }

    return outputFactory.getMaterializingOperator().getMaterializedResult();
  }
  private static LookupSourceSupplier buildHash(
      boolean parallelBuild,
      TaskContext taskContext,
      List<Integer> hashChannels,
      RowPagesBuilder buildPages) {
    if (parallelBuild) {
      ParallelHashBuilder parallelHashBuilder =
          new ParallelHashBuilder(
              buildPages.getTypes(),
              hashChannels,
              buildPages.getHashChannel(),
              100,
              PARTITION_COUNT);

      // collect input data
      DriverContext collectDriverContext =
          taskContext.addPipelineContext(true, true).addDriverContext();
      ValuesOperatorFactory valuesOperatorFactory =
          new ValuesOperatorFactory(
              0, new PlanNodeId("test"), buildPages.getTypes(), buildPages.build());
      OperatorFactory collectOperatorFactory =
          parallelHashBuilder.getCollectOperatorFactory(1, new PlanNodeId("test"));
      Driver driver =
          new Driver(
              collectDriverContext,
              valuesOperatorFactory.createOperator(collectDriverContext),
              collectOperatorFactory.createOperator(collectDriverContext));

      while (!driver.isFinished()) {
        driver.process();
      }

      // build hash tables
      PipelineContext buildPipeline = taskContext.addPipelineContext(true, true);
      OperatorFactory buildOperatorFactory =
          parallelHashBuilder.getBuildOperatorFactory(new PlanNodeId("test"));
      for (int i = 0; i < PARTITION_COUNT; i++) {
        DriverContext buildDriverContext = buildPipeline.addDriverContext();
        Driver buildDriver =
            new Driver(buildDriverContext, buildOperatorFactory.createOperator(buildDriverContext));

        while (!buildDriver.isFinished()) {
          buildDriver.process();
        }
      }

      return parallelHashBuilder.getLookupSourceSupplier();
    } else {
      DriverContext driverContext = taskContext.addPipelineContext(true, true).addDriverContext();

      ValuesOperatorFactory valuesOperatorFactory =
          new ValuesOperatorFactory(
              0, new PlanNodeId("test"), buildPages.getTypes(), buildPages.build());
      HashBuilderOperatorFactory hashBuilderOperatorFactory =
          new HashBuilderOperatorFactory(
              1,
              new PlanNodeId("test"),
              buildPages.getTypes(),
              hashChannels,
              buildPages.getHashChannel(),
              100);

      Driver driver =
          new Driver(
              driverContext,
              valuesOperatorFactory.createOperator(driverContext),
              hashBuilderOperatorFactory.createOperator(driverContext));

      while (!driver.isFinished()) {
        driver.process();
      }
      return hashBuilderOperatorFactory.getLookupSourceSupplier();
    }
  }