Search in sources :

Example 26 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(session, projection, metadata, SYMBOL_TYPES);
    RowExpression projectionRowExpression = toRowExpression(session, projectionExpression);
    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(session.getSqlFunctionProperties(), Optional.empty(), projectionRowExpression, compiler);
    Object directOperatorValue = selectSingleValue(operatorFactory, expectedType, session);
    results.add(directOperatorValue);
    // interpret
    Object interpretedValue = interpret(projectionExpression, expectedType, session);
    results.add(interpretedValue);
    // execute over normal operator
    SourceOperatorFactory scanProjectOperatorFactory = compileScanFilterProject(session.getSqlFunctionProperties(), Optional.empty(), projectionRowExpression, compiler);
    Object scanOperatorValue = selectSingleValue(scanProjectOperatorFactory, expectedType, createNormalSplit(), session);
    results.add(scanOperatorValue);
    // execute over record set
    Object recordValue = selectSingleValue(scanProjectOperatorFactory, expectedType, 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);
    }
    // validate type at end since some tests expect failure and for those UNKNOWN is used instead of actual type
    assertEquals(projectionRowExpression.getType(), expectedType);
    return results;
}
Also used : VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) CanonicalizeExpressionRewriter.canonicalizeExpression(com.facebook.presto.sql.planner.iterative.rule.CanonicalizeExpressionRewriter.canonicalizeExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) Expression(com.facebook.presto.sql.tree.Expression) FilterAndProjectOperatorFactory(com.facebook.presto.operator.FilterAndProjectOperator.FilterAndProjectOperatorFactory) SourceOperatorFactory(com.facebook.presto.operator.SourceOperatorFactory) OperatorFactory(com.facebook.presto.operator.OperatorFactory) ArrayList(java.util.ArrayList) RowExpression(com.facebook.presto.spi.relation.RowExpression) MaterializedResult(com.facebook.presto.testing.MaterializedResult) SourceOperatorFactory(com.facebook.presto.operator.SourceOperatorFactory)

Example 27 with OperatorFactory

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

the class HashBuildBenchmark method createDrivers.

@Override
protected List<Driver> createDrivers(TaskContext taskContext) {
    // hash build
    List<Type> ordersTypes = getColumnTypes("orders", "orderkey", "totalprice");
    OperatorFactory ordersTableScan = createTableScanOperator(0, new PlanNodeId("test"), "orders", "orderkey", "totalprice");
    JoinBridgeManager<PartitionedLookupSourceFactory> lookupSourceFactoryManager = JoinBridgeManager.lookupAllAtOnce(new PartitionedLookupSourceFactory(ordersTypes, ImmutableList.of(0, 1).stream().map(ordersTypes::get).collect(toImmutableList()), Ints.asList(0).stream().map(ordersTypes::get).collect(toImmutableList()), 1, requireNonNull(ImmutableMap.of(), "layout is null"), false));
    HashBuilderOperatorFactory hashBuilder = new HashBuilderOperatorFactory(1, new PlanNodeId("test"), lookupSourceFactoryManager, ImmutableList.of(0, 1), Ints.asList(0), OptionalInt.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(), 1_500_000, new PagesIndex.TestingFactory(false), false, SingleStreamSpillerFactory.unsupportedSingleStreamSpillerFactory(), false);
    DriverFactory hashBuildDriverFactory = new DriverFactory(0, true, true, ImmutableList.of(ordersTableScan, hashBuilder), OptionalInt.empty(), UNGROUPED_EXECUTION, Optional.empty());
    // empty join so build finishes
    ImmutableList.Builder<OperatorFactory> joinDriversBuilder = ImmutableList.builder();
    joinDriversBuilder.add(new ValuesOperatorFactory(0, new PlanNodeId("values"), ImmutableList.of()));
    OperatorFactory joinOperator = LOOKUP_JOIN_OPERATORS.innerJoin(2, new PlanNodeId("test"), lookupSourceFactoryManager, ImmutableList.of(BIGINT), Ints.asList(0), OptionalInt.empty(), Optional.empty(), OptionalInt.empty(), unsupportedPartitioningSpillerFactory());
    joinDriversBuilder.add(joinOperator);
    joinDriversBuilder.add(new NullOutputOperatorFactory(3, new PlanNodeId("test")));
    DriverFactory joinDriverFactory = new DriverFactory(1, true, true, joinDriversBuilder.build(), OptionalInt.empty(), UNGROUPED_EXECUTION, Optional.empty());
    Driver hashBuildDriver = hashBuildDriverFactory.createDriver(taskContext.addPipelineContext(0, true, true, false).addDriverContext());
    hashBuildDriverFactory.noMoreDrivers();
    Driver joinDriver = joinDriverFactory.createDriver(taskContext.addPipelineContext(1, true, true, false).addDriverContext());
    joinDriverFactory.noMoreDrivers();
    return ImmutableList.of(hashBuildDriver, joinDriver);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) HashBuilderOperatorFactory(com.facebook.presto.operator.HashBuilderOperator.HashBuilderOperatorFactory) Driver(com.facebook.presto.operator.Driver) PagesIndex(com.facebook.presto.operator.PagesIndex) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) Type(com.facebook.presto.common.type.Type) OperatorFactory(com.facebook.presto.operator.OperatorFactory) ValuesOperatorFactory(com.facebook.presto.operator.ValuesOperator.ValuesOperatorFactory) HashBuilderOperatorFactory(com.facebook.presto.operator.HashBuilderOperator.HashBuilderOperatorFactory) NullOutputOperatorFactory(com.facebook.presto.testing.NullOutputOperator.NullOutputOperatorFactory) DriverFactory(com.facebook.presto.operator.DriverFactory) ValuesOperatorFactory(com.facebook.presto.operator.ValuesOperator.ValuesOperatorFactory) PartitionedLookupSourceFactory(com.facebook.presto.operator.PartitionedLookupSourceFactory) NullOutputOperatorFactory(com.facebook.presto.testing.NullOutputOperator.NullOutputOperatorFactory)

Example 28 with OperatorFactory

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

the class OrderByBenchmark method createOperatorFactories.

@Override
protected List<? extends OperatorFactory> createOperatorFactories() {
    List<Type> tableScanTypes = getColumnTypes("orders", "totalprice", "clerk");
    OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "orders", "totalprice", "clerk");
    LimitOperatorFactory limitOperator = new LimitOperatorFactory(1, new PlanNodeId("test"), ROWS);
    OrderByOperatorFactory orderByOperator = new OrderByOperatorFactory(2, new PlanNodeId("test"), tableScanTypes, ImmutableList.of(1), ROWS, ImmutableList.of(0), ImmutableList.of(ASC_NULLS_LAST), new PagesIndex.TestingFactory(false), false, Optional.empty(), new OrderingCompiler());
    return ImmutableList.of(tableScanOperator, limitOperator, orderByOperator);
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) Type(com.facebook.presto.common.type.Type) LimitOperatorFactory(com.facebook.presto.operator.LimitOperator.LimitOperatorFactory) OperatorFactory(com.facebook.presto.operator.OperatorFactory) LimitOperatorFactory(com.facebook.presto.operator.LimitOperator.LimitOperatorFactory) OrderByOperatorFactory(com.facebook.presto.operator.OrderByOperator.OrderByOperatorFactory) OrderByOperatorFactory(com.facebook.presto.operator.OrderByOperator.OrderByOperatorFactory) OrderingCompiler(com.facebook.presto.sql.gen.OrderingCompiler) PagesIndex(com.facebook.presto.operator.PagesIndex)

Example 29 with OperatorFactory

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

the class TestUnnestOperator method testUnnestWithOrdinality.

@Test
public void testUnnestWithOrdinality() {
    MetadataManager metadata = createTestMetadataManager();
    Type arrayType = metadata.getType(parseTypeSignature("array(bigint)"));
    Type mapType = metadata.getType(parseTypeSignature("map(bigint,bigint)"));
    List<Page> input = rowPagesBuilder(BIGINT, arrayType, mapType).row(1L, arrayBlockOf(BIGINT, 2, 3), mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(4, 5))).row(2L, arrayBlockOf(BIGINT, 99), null).row(3L, null, null).pageBreak().row(6L, arrayBlockOf(BIGINT, 7, 8), mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(9, 10, 11, 12))).build();
    OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1, 2), ImmutableList.of(arrayType, mapType), true);
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, BIGINT, BIGINT, BIGINT, BIGINT).row(1L, 2L, 4L, 5L, 1L).row(1L, 3L, null, null, 2L).row(2L, 99L, null, null, 1L).row(6L, 7L, 9L, 10L, 1L).row(6L, 8L, 11L, 12L, 2L).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) ArrayType(com.facebook.presto.common.type.ArrayType) Type(com.facebook.presto.common.type.Type) BlockAssertions.createMapType(com.facebook.presto.block.BlockAssertions.createMapType) RowType(com.facebook.presto.common.type.RowType) DecimalType.createDecimalType(com.facebook.presto.common.type.DecimalType.createDecimalType) MetadataManager(com.facebook.presto.metadata.MetadataManager) MetadataManager.createTestMetadataManager(com.facebook.presto.metadata.MetadataManager.createTestMetadataManager) OperatorFactory(com.facebook.presto.operator.OperatorFactory) Page(com.facebook.presto.common.Page) TestUnnesterUtil.buildExpectedPage(com.facebook.presto.operator.unnest.TestUnnesterUtil.buildExpectedPage) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 30 with OperatorFactory

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

the class TestUnnestOperator method testUnnest.

@Test
public void testUnnest() {
    MetadataManager metadata = createTestMetadataManager();
    Type arrayType = metadata.getType(parseTypeSignature("array(bigint)"));
    Type mapType = metadata.getType(parseTypeSignature("map(bigint,bigint)"));
    List<Page> input = rowPagesBuilder(BIGINT, arrayType, mapType).row(1L, arrayBlockOf(BIGINT, 2, 3), mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(4, 5))).row(2L, arrayBlockOf(BIGINT, 99), null).row(3L, null, null).pageBreak().row(6L, arrayBlockOf(BIGINT, 7, 8), mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(9, 10, 11, 12))).build();
    OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1, 2), ImmutableList.of(arrayType, mapType), false);
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, BIGINT, BIGINT, BIGINT).row(1L, 2L, 4L, 5L).row(1L, 3L, null, null).row(2L, 99L, null, null).row(6L, 7L, 9L, 10L).row(6L, 8L, 11L, 12L).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) ArrayType(com.facebook.presto.common.type.ArrayType) Type(com.facebook.presto.common.type.Type) BlockAssertions.createMapType(com.facebook.presto.block.BlockAssertions.createMapType) RowType(com.facebook.presto.common.type.RowType) DecimalType.createDecimalType(com.facebook.presto.common.type.DecimalType.createDecimalType) MetadataManager(com.facebook.presto.metadata.MetadataManager) MetadataManager.createTestMetadataManager(com.facebook.presto.metadata.MetadataManager.createTestMetadataManager) OperatorFactory(com.facebook.presto.operator.OperatorFactory) Page(com.facebook.presto.common.Page) TestUnnesterUtil.buildExpectedPage(com.facebook.presto.operator.unnest.TestUnnesterUtil.buildExpectedPage) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Aggregations

OperatorFactory (com.facebook.presto.operator.OperatorFactory)32 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)23 Type (com.facebook.presto.common.type.Type)13 MaterializedResult (com.facebook.presto.testing.MaterializedResult)11 Page (com.facebook.presto.common.Page)8 DriverContext (com.facebook.presto.operator.DriverContext)8 DriverFactory (com.facebook.presto.operator.DriverFactory)7 ImmutableList (com.google.common.collect.ImmutableList)7 Test (org.testng.annotations.Test)7 BlockAssertions.createMapType (com.facebook.presto.block.BlockAssertions.createMapType)6 ArrayType (com.facebook.presto.common.type.ArrayType)6 DecimalType.createDecimalType (com.facebook.presto.common.type.DecimalType.createDecimalType)6 RowType (com.facebook.presto.common.type.RowType)6 AggregationOperatorFactory (com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory)6 SourceOperatorFactory (com.facebook.presto.operator.SourceOperatorFactory)6 SpatialIndexBuilderOperatorFactory (com.facebook.presto.operator.SpatialIndexBuilderOperator.SpatialIndexBuilderOperatorFactory)6 SpatialJoinOperatorFactory (com.facebook.presto.operator.SpatialJoinOperator.SpatialJoinOperatorFactory)6 MetadataManager (com.facebook.presto.metadata.MetadataManager)5 MetadataManager.createTestMetadataManager (com.facebook.presto.metadata.MetadataManager.createTestMetadataManager)5 HashBuilderOperatorFactory (com.facebook.presto.operator.HashBuilderOperator.HashBuilderOperatorFactory)5