Search in sources :

Example 1 with OperatorFactory

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

the class LocalQueryRunner method createTableScanOperator.

public OperatorFactory createTableScanOperator(Session session, int operatorId, PlanNodeId planNodeId, String tableName, String... columnNames) {
    checkArgument(session.getCatalog().isPresent(), "catalog not set");
    checkArgument(session.getSchema().isPresent(), "schema not set");
    // look up the table
    QualifiedObjectName qualifiedTableName = new QualifiedObjectName(session.getCatalog().get(), session.getSchema().get(), tableName);
    TableHandle tableHandle = metadata.getTableHandle(session, qualifiedTableName).orElse(null);
    checkArgument(tableHandle != null, "Table %s does not exist", qualifiedTableName);
    // lookup the columns
    Map<String, ColumnHandle> allColumnHandles = metadata.getColumnHandles(session, tableHandle);
    ImmutableList.Builder<ColumnHandle> columnHandlesBuilder = ImmutableList.builder();
    ImmutableList.Builder<Type> columnTypesBuilder = ImmutableList.builder();
    for (String columnName : columnNames) {
        ColumnHandle columnHandle = allColumnHandles.get(columnName);
        checkArgument(columnHandle != null, "Table %s does not have a column %s", tableName, columnName);
        columnHandlesBuilder.add(columnHandle);
        ColumnMetadata columnMetadata = metadata.getColumnMetadata(session, tableHandle, columnHandle);
        columnTypesBuilder.add(columnMetadata.getType());
    }
    List<ColumnHandle> columnHandles = columnHandlesBuilder.build();
    List<Type> columnTypes = columnTypesBuilder.build();
    // get the split for this table
    List<TableLayoutResult> layouts = metadata.getLayouts(session, tableHandle, Constraint.alwaysTrue(), Optional.empty());
    Split split = getLocalQuerySplit(session, layouts.get(0).getLayout().getHandle());
    return new OperatorFactory() {

        @Override
        public List<Type> getTypes() {
            return columnTypes;
        }

        @Override
        public Operator createOperator(DriverContext driverContext) {
            OperatorContext operatorContext = driverContext.addOperatorContext(operatorId, planNodeId, "BenchmarkSource");
            ConnectorPageSource pageSource = pageSourceManager.createPageSource(session, split, columnHandles);
            return new PageSourceOperator(pageSource, columnTypes, operatorContext);
        }

        @Override
        public void close() {
        }

        @Override
        public OperatorFactory duplicate() {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) DriverContext(com.facebook.presto.operator.DriverContext) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) ImmutableList(com.google.common.collect.ImmutableList) TableLayoutResult(com.facebook.presto.metadata.TableLayoutResult) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource) QualifiedObjectName(com.facebook.presto.metadata.QualifiedObjectName) PageSourceOperator(com.facebook.presto.operator.PageSourceOperator) Type(com.facebook.presto.spi.type.Type) OperatorFactory(com.facebook.presto.operator.OperatorFactory) OperatorContext(com.facebook.presto.operator.OperatorContext) TableHandle(com.facebook.presto.metadata.TableHandle) ScheduledSplit(com.facebook.presto.ScheduledSplit) Split(com.facebook.presto.metadata.Split)

Example 2 with OperatorFactory

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

the class PredicateFilterBenchmark method createOperatorFactories.

@Override
protected List<? extends OperatorFactory> createOperatorFactories() {
    Metadata metadata = localQueryRunner.getMetadata();
    OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "orders", "totalprice");
    RowExpression filter = call(GREATER_THAN_OR_EQUAL.name(), metadata.getFunctionAndTypeManager().resolveOperator(GREATER_THAN_OR_EQUAL, fromTypes(DOUBLE, DOUBLE)), BOOLEAN, field(0, DOUBLE), constant(50000.0, DOUBLE));
    ExpressionCompiler expressionCompiler = new ExpressionCompiler(metadata, new PageFunctionCompiler(metadata, 0));
    Supplier<PageProcessor> pageProcessor = expressionCompiler.compilePageProcessor(localQueryRunner.getDefaultSession().getSqlFunctionProperties(), Optional.of(filter), ImmutableList.of(field(0, DOUBLE)));
    FilterAndProjectOperator.FilterAndProjectOperatorFactory filterAndProjectOperator = new FilterAndProjectOperator.FilterAndProjectOperatorFactory(1, new PlanNodeId("test"), pageProcessor, ImmutableList.of(DOUBLE), new DataSize(0, BYTE), 0);
    return ImmutableList.of(tableScanOperator, filterAndProjectOperator);
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PageFunctionCompiler(com.facebook.presto.sql.gen.PageFunctionCompiler) PageProcessor(com.facebook.presto.operator.project.PageProcessor) OperatorFactory(com.facebook.presto.operator.OperatorFactory) DataSize(io.airlift.units.DataSize) Metadata(com.facebook.presto.metadata.Metadata) RowExpression(com.facebook.presto.spi.relation.RowExpression) ExpressionCompiler(com.facebook.presto.sql.gen.ExpressionCompiler) FilterAndProjectOperator(com.facebook.presto.operator.FilterAndProjectOperator)

Example 3 with OperatorFactory

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

the class Top100Benchmark method createOperatorFactories.

@Override
protected List<? extends OperatorFactory> createOperatorFactories() {
    List<Type> tableScanTypes = getColumnTypes("orders", "totalprice");
    OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "orders", "totalprice");
    TopNOperatorFactory topNOperator = new TopNOperatorFactory(1, new PlanNodeId("test"), tableScanTypes, 100, ImmutableList.of(0), ImmutableList.of(ASC_NULLS_LAST));
    return ImmutableList.of(tableScanOperator, topNOperator);
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) Type(com.facebook.presto.common.type.Type) OperatorFactory(com.facebook.presto.operator.OperatorFactory) TopNOperatorFactory(com.facebook.presto.operator.TopNOperator.TopNOperatorFactory) TopNOperatorFactory(com.facebook.presto.operator.TopNOperator.TopNOperatorFactory)

Example 4 with OperatorFactory

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

the class TestSpatialJoinOperator method testDistributedSpatialJoin.

@Test
public void testDistributedSpatialJoin() {
    TaskContext taskContext = createTaskContext();
    DriverContext driverContext = taskContext.addPipelineContext(0, true, true, true).addDriverContext();
    RowPagesBuilder buildPages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR, INTEGER));
    addGeometryPartitionRows(buildPages, POLYGON_A, "A");
    buildPages.row(null, "null", null);
    buildPages.pageBreak();
    addGeometryPartitionRows(buildPages, POLYGON_B, "B");
    addGeometryPartitionRows(buildPages, POLYGON_C, "C");
    addGeometryPartitionRows(buildPages, POLYGON_D, "D");
    RowPagesBuilder probePages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR, INTEGER));
    addGeometryPartitionRows(probePages, POINT_X, "x");
    probePages.row(null, "null", null);
    addGeometryPartitionRows(probePages, POINT_Y, "y");
    probePages.pageBreak();
    addGeometryPartitionRows(probePages, POINT_Z, "z");
    addGeometryPartitionRows(probePages, POINT_W, "w");
    addGeometryPartitionRows(probePages, POINT_V, "v");
    addGeometryPartitionRows(probePages, MULTIPOINT_U, "u");
    probePages.pageBreak();
    addGeometryPartitionRows(probePages, MULTIPOINT_T, "t");
    addGeometryPartitionRows(probePages, POINT_S, "s");
    addGeometryPartitionRows(probePages, MULTIPOINT_R, "r");
    addGeometryPartitionRows(probePages, POINT_Q, "q");
    MaterializedResult expected = resultBuilder(taskContext.getSession(), ImmutableList.of(VARCHAR, VARCHAR)).row("x", "A").row("y", "A").row("y", "B").row("z", "B").row("v", "C").row("u", "C").row("t", "C").row("s", "D").row("r", "C").row("r", "D").build();
    PagesSpatialIndexFactory pagesSpatialIndexFactory = buildIndex(driverContext, (build, probe, r) -> build.intersects(probe), Optional.empty(), Optional.of(2), Optional.of(KDB_TREE_JSON), Optional.empty(), buildPages);
    OperatorFactory joinOperatorFactory = new SpatialJoinOperatorFactory(2, new PlanNodeId("test"), INNER, probePages.getTypes(), Ints.asList(1), 0, Optional.of(2), pagesSpatialIndexFactory);
    assertOperatorEqualsIgnoreOrder(joinOperatorFactory, driverContext, probePages.build(), expected);
}
Also used : SpatialJoinOperatorFactory(com.facebook.presto.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) DriverContext(com.facebook.presto.operator.DriverContext) TestingTaskContext(com.facebook.presto.testing.TestingTaskContext) TaskContext(com.facebook.presto.operator.TaskContext) RowPagesBuilder(com.facebook.presto.RowPagesBuilder) SpatialJoinOperatorFactory(com.facebook.presto.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) OperatorFactory(com.facebook.presto.operator.OperatorFactory) SpatialIndexBuilderOperatorFactory(com.facebook.presto.operator.SpatialIndexBuilderOperator.SpatialIndexBuilderOperatorFactory) MaterializedResult(com.facebook.presto.testing.MaterializedResult) PagesSpatialIndexFactory(com.facebook.presto.operator.PagesSpatialIndexFactory) Test(org.testng.annotations.Test)

Example 5 with OperatorFactory

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

the class TestSpatialJoinOperator method testDistributedSpatialSelfJoin.

@Test
public void testDistributedSpatialSelfJoin() {
    TaskContext taskContext = createTaskContext();
    DriverContext driverContext = taskContext.addPipelineContext(0, true, true, true).addDriverContext();
    RowPagesBuilder pages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR, INTEGER));
    addGeometryPartitionRows(pages, POLYGON_A, "A");
    pages.row(null, "null", null);
    pages.pageBreak();
    addGeometryPartitionRows(pages, POLYGON_B, "B");
    MaterializedResult expected = resultBuilder(taskContext.getSession(), ImmutableList.of(VARCHAR, VARCHAR)).row("A", "A").row("A", "B").row("B", "A").row("B", "B").build();
    PagesSpatialIndexFactory pagesSpatialIndexFactory = buildIndex(driverContext, (build, probe, r) -> build.intersects(probe), Optional.empty(), Optional.of(2), Optional.of(KDB_TREE_JSON), Optional.empty(), pages);
    OperatorFactory joinOperatorFactory = new SpatialJoinOperatorFactory(2, new PlanNodeId("test"), INNER, pages.getTypes(), Ints.asList(1), 0, Optional.of(2), pagesSpatialIndexFactory);
    assertOperatorEqualsIgnoreOrder(joinOperatorFactory, driverContext, pages.build(), expected);
}
Also used : SpatialJoinOperatorFactory(com.facebook.presto.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) DriverContext(com.facebook.presto.operator.DriverContext) TestingTaskContext(com.facebook.presto.testing.TestingTaskContext) TaskContext(com.facebook.presto.operator.TaskContext) RowPagesBuilder(com.facebook.presto.RowPagesBuilder) SpatialJoinOperatorFactory(com.facebook.presto.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) OperatorFactory(com.facebook.presto.operator.OperatorFactory) SpatialIndexBuilderOperatorFactory(com.facebook.presto.operator.SpatialIndexBuilderOperator.SpatialIndexBuilderOperatorFactory) MaterializedResult(com.facebook.presto.testing.MaterializedResult) PagesSpatialIndexFactory(com.facebook.presto.operator.PagesSpatialIndexFactory) 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