Search in sources :

Example 16 with OperatorFactory

use of com.facebook.presto.operator.OperatorFactory in project presto by prestodb.

the class HashBuildAndJoinBenchmark method createDrivers.

/*
    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(), ImmutableList.of(0, 1), ImmutableMap.of(), Ints.asList(0), hashChannel, false, Optional.empty(), 1_500_000, 1, new PagesIndex.TestingFactory());
    driversBuilder.add(hashBuilder);
    DriverFactory hashBuildDriverFactory = new DriverFactory(0, true, false, driversBuilder.build(), OptionalInt.empty());
    Driver hashBuildDriver = hashBuildDriverFactory.createDriver(taskContext.addPipelineContext(0, 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 = LOOKUP_JOIN_OPERATORS.innerJoin(2, new PlanNodeId("test"), hashBuilder.getLookupSourceFactory(), source.getTypes(), Ints.asList(0), hashChannel, Optional.empty());
    joinDriversBuilder.add(joinOperator);
    joinDriversBuilder.add(new NullOutputOperatorFactory(3, new PlanNodeId("test"), joinOperator.getTypes()));
    DriverFactory joinDriverFactory = new DriverFactory(1, true, true, joinDriversBuilder.build(), OptionalInt.empty());
    Driver joinDriver = joinDriverFactory.createDriver(taskContext.addPipelineContext(1, true, true).addDriverContext());
    joinDriverFactory.close();
    return ImmutableList.of(hashBuildDriver, joinDriver);
}
Also used : PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) ImmutableList(com.google.common.collect.ImmutableList) HashBuilderOperatorFactory(com.facebook.presto.operator.HashBuilderOperator.HashBuilderOperatorFactory) OperatorFactory(com.facebook.presto.operator.OperatorFactory) NullOutputOperatorFactory(com.facebook.presto.testing.NullOutputOperator.NullOutputOperatorFactory) DriverFactory(com.facebook.presto.operator.DriverFactory) HashBuilderOperatorFactory(com.facebook.presto.operator.HashBuilderOperator.HashBuilderOperatorFactory) Driver(com.facebook.presto.operator.Driver) PagesIndex(com.facebook.presto.operator.PagesIndex) NullOutputOperatorFactory(com.facebook.presto.testing.NullOutputOperator.NullOutputOperatorFactory)

Example 17 with OperatorFactory

use of com.facebook.presto.operator.OperatorFactory in project presto by prestodb.

the class FunctionAssertions method interpretedFilterProject.

private Operator interpretedFilterProject(Expression filter, Expression projection, Session session) {
    FilterFunction filterFunction = new InterpretedInternalFilterFunction(filter, SYMBOL_TYPES, INPUT_MAPPING, metadata, SQL_PARSER, session);
    ProjectionFunction projectionFunction = new InterpretedProjectionFunction(projection, SYMBOL_TYPES, INPUT_MAPPING, metadata, SQL_PARSER, session);
    OperatorFactory operatorFactory = new FilterAndProjectOperator.FilterAndProjectOperatorFactory(0, new PlanNodeId("test"), () -> new GenericPageProcessor(filterFunction, ImmutableList.of(projectionFunction)), toTypes(ImmutableList.of(projectionFunction)));
    return operatorFactory.createOperator(createDriverContext(session));
}
Also used : PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) ProjectionFunction(com.facebook.presto.operator.ProjectionFunction) InterpretedProjectionFunction(com.facebook.presto.sql.planner.InterpretedProjectionFunction) FilterFunction(com.facebook.presto.operator.FilterFunction) InterpretedInternalFilterFunction(com.facebook.presto.sql.planner.InterpretedInternalFilterFunction) SourceOperatorFactory(com.facebook.presto.operator.SourceOperatorFactory) OperatorFactory(com.facebook.presto.operator.OperatorFactory) InterpretedInternalFilterFunction(com.facebook.presto.sql.planner.InterpretedInternalFilterFunction) InterpretedProjectionFunction(com.facebook.presto.sql.planner.InterpretedProjectionFunction) GenericPageProcessor(com.facebook.presto.operator.GenericPageProcessor)

Example 18 with OperatorFactory

use of com.facebook.presto.operator.OperatorFactory in project presto by prestodb.

the class FunctionAssertions method executeProjectionWithAll.

private List<Object> executeProjectionWithAll(String projection, Type expectedType, Session session, ExpressionCompiler compiler) {
    requireNonNull(projection, "projection is null");
    Expression projectionExpression = createExpression(projection, metadata, SYMBOL_TYPES);
    List<Object> results = new ArrayList<>();
    // If the projection does not need bound values, execute query using full engine
    if (!needsBoundValue(projectionExpression)) {
        MaterializedResult result = runner.execute("SELECT " + projection);
        assertType(result.getTypes(), expectedType);
        assertEquals(result.getTypes().size(), 1);
        assertEquals(result.getMaterializedRows().size(), 1);
        Object queryResult = Iterables.getOnlyElement(result.getMaterializedRows()).getField(0);
        results.add(queryResult);
    }
    // execute as standalone operator
    OperatorFactory operatorFactory = compileFilterProject(TRUE_LITERAL, projectionExpression, compiler);
    assertType(operatorFactory.getTypes(), expectedType);
    Object directOperatorValue = selectSingleValue(operatorFactory, session);
    results.add(directOperatorValue);
    // interpret
    Operator interpretedFilterProject = interpretedFilterProject(TRUE_LITERAL, projectionExpression, session);
    assertType(interpretedFilterProject.getTypes(), expectedType);
    Object interpretedValue = selectSingleValue(interpretedFilterProject);
    results.add(interpretedValue);
    // execute over normal operator
    SourceOperatorFactory scanProjectOperatorFactory = compileScanFilterProject(TRUE_LITERAL, projectionExpression, compiler);
    assertType(scanProjectOperatorFactory.getTypes(), expectedType);
    Object scanOperatorValue = selectSingleValue(scanProjectOperatorFactory, createNormalSplit(), session);
    results.add(scanOperatorValue);
    // execute over record set
    Object recordValue = selectSingleValue(scanProjectOperatorFactory, createRecordSetSplit(), session);
    results.add(recordValue);
    // If the projection does not need bound values, execute query using full engine
    if (!needsBoundValue(projectionExpression)) {
        MaterializedResult result = runner.execute("SELECT " + projection);
        assertType(result.getTypes(), expectedType);
        assertEquals(result.getTypes().size(), 1);
        assertEquals(result.getMaterializedRows().size(), 1);
        Object queryResult = Iterables.getOnlyElement(result.getMaterializedRows()).getField(0);
        results.add(queryResult);
    }
    return results;
}
Also used : FilterAndProjectOperator(com.facebook.presto.operator.FilterAndProjectOperator) Operator(com.facebook.presto.operator.Operator) SourceOperator(com.facebook.presto.operator.SourceOperator) ScanFilterAndProjectOperator(com.facebook.presto.operator.ScanFilterAndProjectOperator) RowExpression(com.facebook.presto.sql.relational.RowExpression) CanonicalizeExpressions.canonicalizeExpression(com.facebook.presto.sql.planner.optimizations.CanonicalizeExpressions.canonicalizeExpression) DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) Expression(com.facebook.presto.sql.tree.Expression) SourceOperatorFactory(com.facebook.presto.operator.SourceOperatorFactory) OperatorFactory(com.facebook.presto.operator.OperatorFactory) ArrayList(java.util.ArrayList) MaterializedResult(com.facebook.presto.testing.MaterializedResult) SourceOperatorFactory(com.facebook.presto.operator.SourceOperatorFactory)

Example 19 with OperatorFactory

use of com.facebook.presto.operator.OperatorFactory in project presto by prestodb.

the class IndexBuildDriverFactoryProvider method createStreaming.

public DriverFactory createStreaming(PageBuffer pageBuffer, Page indexKeyTuple) {
    ImmutableList.Builder<OperatorFactory> operatorFactories = ImmutableList.<OperatorFactory>builder().addAll(coreOperatorFactories);
    if (dynamicTupleFilterFactory.isPresent()) {
        // Bind in a dynamic tuple filter if necessary
        operatorFactories.add(dynamicTupleFilterFactory.get().filterWithTuple(indexKeyTuple));
    }
    operatorFactories.add(new PageBufferOperatorFactory(outputOperatorId, planNodeId, pageBuffer));
    return new DriverFactory(pipelineId, inputDriver, false, operatorFactories.build(), OptionalInt.empty());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) PageBufferOperatorFactory(com.facebook.presto.operator.index.PageBufferOperator.PageBufferOperatorFactory) OperatorFactory(com.facebook.presto.operator.OperatorFactory) PagesIndexBuilderOperatorFactory(com.facebook.presto.operator.index.PagesIndexBuilderOperator.PagesIndexBuilderOperatorFactory) DriverFactory(com.facebook.presto.operator.DriverFactory) PageBufferOperatorFactory(com.facebook.presto.operator.index.PageBufferOperator.PageBufferOperatorFactory)

Aggregations

OperatorFactory (com.facebook.presto.operator.OperatorFactory)19 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)13 DriverFactory (com.facebook.presto.operator.DriverFactory)7 AggregationOperatorFactory (com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory)5 HashBuilderOperatorFactory (com.facebook.presto.operator.HashBuilderOperator.HashBuilderOperatorFactory)5 SourceOperatorFactory (com.facebook.presto.operator.SourceOperatorFactory)5 ImmutableList (com.google.common.collect.ImmutableList)5 HashAggregationOperatorFactory (com.facebook.presto.operator.HashAggregationOperator.HashAggregationOperatorFactory)4 PagesIndex (com.facebook.presto.operator.PagesIndex)4 NullOutputOperatorFactory (com.facebook.presto.testing.NullOutputOperator.NullOutputOperatorFactory)4 Driver (com.facebook.presto.operator.Driver)3 FilterAndProjectOperator (com.facebook.presto.operator.FilterAndProjectOperator)3 LimitOperatorFactory (com.facebook.presto.operator.LimitOperator.LimitOperatorFactory)3 OrderByOperatorFactory (com.facebook.presto.operator.OrderByOperator.OrderByOperatorFactory)3 ValuesOperatorFactory (com.facebook.presto.operator.ValuesOperator.ValuesOperatorFactory)3 Signature (com.facebook.presto.metadata.Signature)2 DeleteOperatorFactory (com.facebook.presto.operator.DeleteOperator.DeleteOperatorFactory)2 DistinctLimitOperatorFactory (com.facebook.presto.operator.DistinctLimitOperator.DistinctLimitOperatorFactory)2 DriverContext (com.facebook.presto.operator.DriverContext)2 ExchangeOperatorFactory (com.facebook.presto.operator.ExchangeOperator.ExchangeOperatorFactory)2