@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); }
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(); } }
/* 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); }