Beispiel #1
0
  @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);
  }
  /*
  select orderkey, quantity, totalprice
  from lineitem join orders using (orderkey)
   */
  @Override
  protected List<Driver> createDrivers(TaskContext taskContext) {
    ImmutableList.Builder<OperatorFactory> driversBuilder = ImmutableList.builder();
    driversBuilder.add(ordersTableScan);
    OperatorFactory source = ordersTableScan;
    Optional<Integer> hashChannel = Optional.empty();
    if (hashEnabled) {
      source =
          createHashProjectOperator(1, new PlanNodeId("test"), ImmutableList.of(BIGINT, DOUBLE));
      driversBuilder.add(source);
      hashChannel = Optional.of(2);
    }

    // hash build
    HashBuilderOperatorFactory hashBuilder =
        new HashBuilderOperatorFactory(
            2,
            new PlanNodeId("test"),
            source.getTypes(),
            ImmutableMap.of(),
            Ints.asList(0),
            hashChannel,
            false,
            Optional.empty(),
            1_500_000,
            1);
    driversBuilder.add(hashBuilder);
    DriverFactory hashBuildDriverFactory =
        new DriverFactory(true, false, driversBuilder.build(), OptionalInt.empty());
    Driver hashBuildDriver =
        hashBuildDriverFactory.createDriver(
            taskContext.addPipelineContext(true, false).addDriverContext());
    hashBuildDriverFactory.close();

    // join
    ImmutableList.Builder<OperatorFactory> joinDriversBuilder = ImmutableList.builder();
    joinDriversBuilder.add(lineItemTableScan);
    source = lineItemTableScan;
    hashChannel = Optional.empty();
    if (hashEnabled) {
      source =
          createHashProjectOperator(1, new PlanNodeId("test"), ImmutableList.of(BIGINT, BIGINT));
      joinDriversBuilder.add(source);
      hashChannel = Optional.of(2);
    }

    OperatorFactory joinOperator =
        LookupJoinOperators.innerJoin(
            2,
            new PlanNodeId("test"),
            hashBuilder.getLookupSourceFactory(),
            source.getTypes(),
            Ints.asList(0),
            hashChannel,
            false);
    joinDriversBuilder.add(joinOperator);
    joinDriversBuilder.add(
        new NullOutputOperatorFactory(3, new PlanNodeId("test"), joinOperator.getTypes()));
    DriverFactory joinDriverFactory =
        new DriverFactory(true, true, joinDriversBuilder.build(), OptionalInt.empty());
    Driver joinDriver =
        joinDriverFactory.createDriver(
            taskContext.addPipelineContext(true, true).addDriverContext());
    joinDriverFactory.close();

    return ImmutableList.of(hashBuildDriver, joinDriver);
  }