Search in sources :

Example 21 with OperatorFactory

use of io.prestosql.operator.OperatorFactory in project hetu-core by openlookeng.

the class TestSpatialJoinOperator method testDuplicateProbeFactory.

@Test(dataProvider = "testDuplicateProbeFactoryDataProvider")
public void testDuplicateProbeFactory(boolean createSecondaryOperators) throws Exception {
    TaskContext taskContext = createTaskContext();
    PipelineContext pipelineContext = taskContext.addPipelineContext(0, true, true, false);
    DriverContext probeDriver = pipelineContext.addDriverContext();
    DriverContext buildDriver = pipelineContext.addDriverContext();
    RowPagesBuilder buildPages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR, DOUBLE)).row(stPoint(0, 0), "0_0", 1.5);
    PagesSpatialIndexFactory pagesSpatialIndexFactory = buildIndex(buildDriver, (build, probe, r) -> build.distance(probe) <= r.getAsDouble(), Optional.of(2), Optional.empty(), buildPages);
    RowPagesBuilder probePages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR)).row(stPoint(0, 1), "0_1");
    OperatorFactory firstFactory = new SpatialJoinOperatorFactory(2, new PlanNodeId("test"), INNER, probePages.getTypes(), Ints.asList(1), 0, Optional.empty(), pagesSpatialIndexFactory);
    for (int i = 0; i < 3; i++) {
        DriverContext secondDriver = pipelineContext.addDriverContext();
        OperatorFactory secondFactory = firstFactory.duplicate();
        if (createSecondaryOperators) {
            try (Operator secondOperator = secondFactory.createOperator(secondDriver)) {
                assertEquals(toPages(secondOperator, emptyIterator()), ImmutableList.of());
            }
        }
        secondFactory.noMoreOperators();
    }
    MaterializedResult expected = resultBuilder(taskContext.getSession(), ImmutableList.of(VARCHAR, VARCHAR)).row("0_1", "0_0").build();
    assertOperatorEquals(firstFactory, probeDriver, probePages.build(), expected);
}
Also used : SpatialJoinOperatorFactory(io.prestosql.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) ValuesOperator(io.prestosql.operator.ValuesOperator) Operator(io.prestosql.operator.Operator) DriverContext(io.prestosql.operator.DriverContext) TaskContext(io.prestosql.operator.TaskContext) TestingTaskContext(io.prestosql.testing.TestingTaskContext) RowPagesBuilder(io.prestosql.RowPagesBuilder) PipelineContext(io.prestosql.operator.PipelineContext) SpatialJoinOperatorFactory(io.prestosql.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) OperatorFactory(io.prestosql.operator.OperatorFactory) SpatialIndexBuilderOperatorFactory(io.prestosql.operator.SpatialIndexBuilderOperator.SpatialIndexBuilderOperatorFactory) PagesSpatialIndexFactory(io.prestosql.operator.PagesSpatialIndexFactory) MaterializedResult(io.prestosql.testing.MaterializedResult) OperatorAssertion.toMaterializedResult(io.prestosql.operator.OperatorAssertion.toMaterializedResult) GeoFunctions.stPoint(io.prestosql.plugin.geospatial.GeoFunctions.stPoint) Test(org.testng.annotations.Test)

Example 22 with OperatorFactory

use of io.prestosql.operator.OperatorFactory in project hetu-core by openlookeng.

the class LocalExecutionPlanner method plan.

public LocalExecutionPlan plan(TaskContext taskContext, StageExecutionDescriptor stageExecutionDescriptor, PlanNode plan, List<Symbol> outputLayout, TypeProvider types, List<PlanNodeId> partitionedSourceOrder, OutputBuffer outputBuffer, OutputFactory outputOperatorFactory, Optional<PlanFragmentId> feederCTEId, Optional<PlanNodeId> feederCTEParentId, Map<String, CommonTableExecutionContext> cteCtx) {
    Session session = taskContext.getSession();
    LocalExecutionPlanContext context = new LocalExecutionPlanContext(taskContext, types, metadata, dynamicFilterCacheManager, feederCTEId, feederCTEParentId, cteCtx);
    PhysicalOperation physicalOperation = plan.accept(new Visitor(session, stageExecutionDescriptor), context);
    Function<Page, Page> pagePreprocessor = enforceLayoutProcessor(outputLayout, physicalOperation.getLayout());
    List<Type> outputTypes = outputLayout.stream().map(types::get).collect(toImmutableList());
    context.addDriverFactory(context.isInputDriver(), true, ImmutableList.<OperatorFactory>builder().addAll(physicalOperation.getOperatorFactories()).add(outputOperatorFactory.createOutputOperator(context.getNextOperatorId(), plan.getId(), outputTypes, pagePreprocessor, taskContext)).build(), context.getDriverInstanceCount(), physicalOperation.getPipelineExecutionStrategy());
    addLookupOuterDrivers(context);
    // notify operator factories that planning has completed
    context.getDriverFactories().stream().map(DriverFactory::getOperatorFactories).flatMap(List::stream).filter(LocalPlannerAware.class::isInstance).map(LocalPlannerAware.class::cast).forEach(LocalPlannerAware::localPlannerComplete);
    // calculate total number of components to be captured and add to snapshotManager
    if (SystemSessionProperties.isSnapshotEnabled(session)) {
        taskContext.getSnapshotManager().setTotalComponents(calculateTotalCountOfTaskComponentToBeCaptured(taskContext, context, outputBuffer));
    }
    return new LocalExecutionPlan(context.getDriverFactories(), partitionedSourceOrder, stageExecutionDescriptor, feederCTEId);
}
Also used : Type(io.prestosql.spi.type.Type) OperatorType(io.prestosql.spi.function.OperatorType) InternalPlanVisitor(io.prestosql.sql.planner.plan.InternalPlanVisitor) HashSemiJoinOperatorFactory(io.prestosql.operator.HashSemiJoinOperator.HashSemiJoinOperatorFactory) StatisticsWriterOperatorFactory(io.prestosql.operator.StatisticsWriterOperator.StatisticsWriterOperatorFactory) SetBuilderOperatorFactory(io.prestosql.operator.SetBuilderOperator.SetBuilderOperatorFactory) MergeOperatorFactory(io.prestosql.operator.MergeOperator.MergeOperatorFactory) ExchangeOperatorFactory(io.prestosql.operator.ExchangeOperator.ExchangeOperatorFactory) UnnestOperatorFactory(io.prestosql.operator.unnest.UnnestOperator.UnnestOperatorFactory) LocalExchangeSinkOperatorFactory(io.prestosql.operator.exchange.LocalExchangeSinkOperator.LocalExchangeSinkOperatorFactory) TopNOperatorFactory(io.prestosql.operator.TopNOperator.TopNOperatorFactory) HashBuilderOperatorFactory(io.prestosql.operator.HashBuilderOperator.HashBuilderOperatorFactory) LimitOperatorFactory(io.prestosql.operator.LimitOperator.LimitOperatorFactory) DeleteOperatorFactory(io.prestosql.operator.DeleteOperator.DeleteOperatorFactory) DevNullOperatorFactory(io.prestosql.operator.DevNullOperator.DevNullOperatorFactory) LookupOuterOperatorFactory(io.prestosql.operator.LookupOuterOperator.LookupOuterOperatorFactory) OrderByOperatorFactory(io.prestosql.operator.OrderByOperator.OrderByOperatorFactory) TableWriterOperatorFactory(io.prestosql.operator.TableWriterOperator.TableWriterOperatorFactory) WindowOperatorFactory(io.prestosql.operator.WindowOperator.WindowOperatorFactory) SpatialIndexBuilderOperatorFactory(io.prestosql.operator.SpatialIndexBuilderOperator.SpatialIndexBuilderOperatorFactory) JoinOperatorFactory(io.prestosql.operator.JoinOperatorFactory) CreateIndexOperatorFactory(io.prestosql.operator.CreateIndexOperator.CreateIndexOperatorFactory) LookupJoinOperatorFactory(io.prestosql.operator.LookupJoinOperatorFactory) ExplainAnalyzeOperatorFactory(io.prestosql.operator.ExplainAnalyzeOperator.ExplainAnalyzeOperatorFactory) MarkDistinctOperatorFactory(io.prestosql.operator.MarkDistinctOperator.MarkDistinctOperatorFactory) CommonTableExpressionOperatorFactory(io.prestosql.operator.CommonTableExpressionOperator.CommonTableExpressionOperatorFactory) SourceOperatorFactory(io.prestosql.operator.SourceOperatorFactory) OperatorFactory(io.prestosql.operator.OperatorFactory) NestedLoopBuildOperatorFactory(io.prestosql.operator.NestedLoopBuildOperator.NestedLoopBuildOperatorFactory) DistinctLimitOperatorFactory(io.prestosql.operator.DistinctLimitOperator.DistinctLimitOperatorFactory) ValuesOperatorFactory(io.prestosql.operator.ValuesOperator.ValuesOperatorFactory) CubeFinishOperatorFactory(io.prestosql.operator.CubeFinishOperator.CubeFinishOperatorFactory) SpatialJoinOperatorFactory(io.prestosql.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) TableDeleteOperatorFactory(io.prestosql.operator.TableDeleteOperator.TableDeleteOperatorFactory) HashAggregationOperatorFactory(io.prestosql.operator.HashAggregationOperator.HashAggregationOperatorFactory) AggregationOperatorFactory(io.prestosql.operator.AggregationOperator.AggregationOperatorFactory) TableScanOperatorFactory(io.prestosql.operator.TableScanOperator.TableScanOperatorFactory) LocalMergeSourceOperatorFactory(io.prestosql.operator.exchange.LocalMergeSourceOperator.LocalMergeSourceOperatorFactory) StreamingAggregationOperatorFactory(io.prestosql.operator.StreamingAggregationOperator.StreamingAggregationOperatorFactory) NestedLoopJoinOperatorFactory(io.prestosql.operator.NestedLoopJoinOperator.NestedLoopJoinOperatorFactory) ScanFilterAndProjectOperatorFactory(io.prestosql.operator.ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory) LocalExchangeSourceOperatorFactory(io.prestosql.operator.exchange.LocalExchangeSourceOperator.LocalExchangeSourceOperatorFactory) TableFinishOperatorFactory(io.prestosql.operator.TableFinishOperator.TableFinishOperatorFactory) DriverFactory(io.prestosql.operator.DriverFactory) Page(io.prestosql.spi.Page) MarkerPage(io.prestosql.spi.snapshot.MarkerPage) LocalPlannerAware(io.prestosql.operator.LocalPlannerAware) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Session(io.prestosql.Session)

Example 23 with OperatorFactory

use of io.prestosql.operator.OperatorFactory in project hetu-core by openlookeng.

the class LocalExecutionPlanner method addLookupOuterDrivers.

private static void addLookupOuterDrivers(LocalExecutionPlanContext context) {
    // driver to output the unused rows in the lookup source
    for (DriverFactory factory : context.getDriverFactories()) {
        List<OperatorFactory> operatorFactories = factory.getOperatorFactories();
        for (int i = 0; i < operatorFactories.size(); i++) {
            OperatorFactory operatorFactory = operatorFactories.get(i);
            if (!(operatorFactory instanceof JoinOperatorFactory)) {
                continue;
            }
            JoinOperatorFactory lookupJoin = (JoinOperatorFactory) operatorFactory;
            Optional<OuterOperatorFactoryResult> outerOperatorFactoryResult = lookupJoin.createOuterOperatorFactory();
            if (outerOperatorFactoryResult.isPresent()) {
                // Add a new driver to output the unmatched rows in an outer join.
                // We duplicate all of the factories above the JoinOperator (the ones reading from the joins),
                // and replace the JoinOperator with the OuterOperator (the one that produces unmatched rows).
                ImmutableList.Builder<OperatorFactory> newOperators = ImmutableList.builder();
                newOperators.add(outerOperatorFactoryResult.get().getOuterOperatorFactory());
                operatorFactories.subList(i + 1, operatorFactories.size()).stream().map(OperatorFactory::duplicate).forEach(newOperators::add);
                DriverFactory outerFactory = context.addDriverFactory(false, factory.isOutputDriver(), newOperators.build(), OptionalInt.of(1), outerOperatorFactoryResult.get().getBuildExecutionStrategy());
                context.outerToJoinMap.put(outerFactory, factory);
            }
        }
    }
}
Also used : HashSemiJoinOperatorFactory(io.prestosql.operator.HashSemiJoinOperator.HashSemiJoinOperatorFactory) StatisticsWriterOperatorFactory(io.prestosql.operator.StatisticsWriterOperator.StatisticsWriterOperatorFactory) SetBuilderOperatorFactory(io.prestosql.operator.SetBuilderOperator.SetBuilderOperatorFactory) MergeOperatorFactory(io.prestosql.operator.MergeOperator.MergeOperatorFactory) ExchangeOperatorFactory(io.prestosql.operator.ExchangeOperator.ExchangeOperatorFactory) UnnestOperatorFactory(io.prestosql.operator.unnest.UnnestOperator.UnnestOperatorFactory) LocalExchangeSinkOperatorFactory(io.prestosql.operator.exchange.LocalExchangeSinkOperator.LocalExchangeSinkOperatorFactory) TopNOperatorFactory(io.prestosql.operator.TopNOperator.TopNOperatorFactory) HashBuilderOperatorFactory(io.prestosql.operator.HashBuilderOperator.HashBuilderOperatorFactory) LimitOperatorFactory(io.prestosql.operator.LimitOperator.LimitOperatorFactory) DeleteOperatorFactory(io.prestosql.operator.DeleteOperator.DeleteOperatorFactory) DevNullOperatorFactory(io.prestosql.operator.DevNullOperator.DevNullOperatorFactory) LookupOuterOperatorFactory(io.prestosql.operator.LookupOuterOperator.LookupOuterOperatorFactory) OrderByOperatorFactory(io.prestosql.operator.OrderByOperator.OrderByOperatorFactory) TableWriterOperatorFactory(io.prestosql.operator.TableWriterOperator.TableWriterOperatorFactory) WindowOperatorFactory(io.prestosql.operator.WindowOperator.WindowOperatorFactory) SpatialIndexBuilderOperatorFactory(io.prestosql.operator.SpatialIndexBuilderOperator.SpatialIndexBuilderOperatorFactory) JoinOperatorFactory(io.prestosql.operator.JoinOperatorFactory) CreateIndexOperatorFactory(io.prestosql.operator.CreateIndexOperator.CreateIndexOperatorFactory) LookupJoinOperatorFactory(io.prestosql.operator.LookupJoinOperatorFactory) ExplainAnalyzeOperatorFactory(io.prestosql.operator.ExplainAnalyzeOperator.ExplainAnalyzeOperatorFactory) MarkDistinctOperatorFactory(io.prestosql.operator.MarkDistinctOperator.MarkDistinctOperatorFactory) CommonTableExpressionOperatorFactory(io.prestosql.operator.CommonTableExpressionOperator.CommonTableExpressionOperatorFactory) SourceOperatorFactory(io.prestosql.operator.SourceOperatorFactory) OperatorFactory(io.prestosql.operator.OperatorFactory) NestedLoopBuildOperatorFactory(io.prestosql.operator.NestedLoopBuildOperator.NestedLoopBuildOperatorFactory) DistinctLimitOperatorFactory(io.prestosql.operator.DistinctLimitOperator.DistinctLimitOperatorFactory) ValuesOperatorFactory(io.prestosql.operator.ValuesOperator.ValuesOperatorFactory) CubeFinishOperatorFactory(io.prestosql.operator.CubeFinishOperator.CubeFinishOperatorFactory) SpatialJoinOperatorFactory(io.prestosql.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) TableDeleteOperatorFactory(io.prestosql.operator.TableDeleteOperator.TableDeleteOperatorFactory) HashAggregationOperatorFactory(io.prestosql.operator.HashAggregationOperator.HashAggregationOperatorFactory) AggregationOperatorFactory(io.prestosql.operator.AggregationOperator.AggregationOperatorFactory) TableScanOperatorFactory(io.prestosql.operator.TableScanOperator.TableScanOperatorFactory) LocalMergeSourceOperatorFactory(io.prestosql.operator.exchange.LocalMergeSourceOperator.LocalMergeSourceOperatorFactory) StreamingAggregationOperatorFactory(io.prestosql.operator.StreamingAggregationOperator.StreamingAggregationOperatorFactory) NestedLoopJoinOperatorFactory(io.prestosql.operator.NestedLoopJoinOperator.NestedLoopJoinOperatorFactory) ScanFilterAndProjectOperatorFactory(io.prestosql.operator.ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory) LocalExchangeSourceOperatorFactory(io.prestosql.operator.exchange.LocalExchangeSourceOperator.LocalExchangeSourceOperatorFactory) TableFinishOperatorFactory(io.prestosql.operator.TableFinishOperator.TableFinishOperatorFactory) HashSemiJoinOperatorFactory(io.prestosql.operator.HashSemiJoinOperator.HashSemiJoinOperatorFactory) JoinOperatorFactory(io.prestosql.operator.JoinOperatorFactory) LookupJoinOperatorFactory(io.prestosql.operator.LookupJoinOperatorFactory) SpatialJoinOperatorFactory(io.prestosql.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) NestedLoopJoinOperatorFactory(io.prestosql.operator.NestedLoopJoinOperator.NestedLoopJoinOperatorFactory) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) DriverFactory(io.prestosql.operator.DriverFactory) OuterOperatorFactoryResult(io.prestosql.operator.JoinOperatorFactory.OuterOperatorFactoryResult)

Example 24 with OperatorFactory

use of io.prestosql.operator.OperatorFactory in project hetu-core by openlookeng.

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(), UNGROUPED_EXECUTION);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) OperatorFactory(io.prestosql.operator.OperatorFactory) PagesIndexBuilderOperatorFactory(io.prestosql.operator.index.PagesIndexBuilderOperator.PagesIndexBuilderOperatorFactory) PageBufferOperatorFactory(io.prestosql.operator.index.PageBufferOperator.PageBufferOperatorFactory) DriverFactory(io.prestosql.operator.DriverFactory) PageBufferOperatorFactory(io.prestosql.operator.index.PageBufferOperator.PageBufferOperatorFactory)

Example 25 with OperatorFactory

use of io.prestosql.operator.OperatorFactory in project hetu-core by openlookeng.

the class FunctionAssertions method executeFilterWithAll.

private List<Boolean> executeFilterWithAll(String filter, Session session, boolean executeWithNoInputColumns, ExpressionCompiler compiler) {
    requireNonNull(filter, "filter is null");
    Expression filterExpression = createExpression(session, filter, metadata, TypeProvider.copyOf(INPUT_TYPES));
    RowExpression filterRowExpression = toRowExpression(session, filterExpression);
    List<Boolean> results = new ArrayList<>();
    // execute as standalone operator
    OperatorFactory operatorFactory = compileFilterProject(Optional.of(filterRowExpression), constant(true, BOOLEAN), compiler);
    results.add(executeFilter(operatorFactory, session));
    if (executeWithNoInputColumns) {
        // execute as standalone operator
        operatorFactory = compileFilterWithNoInputColumns(filterRowExpression, compiler);
        results.add(executeFilterWithNoInputColumns(operatorFactory, session));
    }
    // interpret
    Boolean interpretedValue = (Boolean) interpret(filterExpression, BOOLEAN, session);
    if (interpretedValue == null) {
        interpretedValue = false;
    }
    results.add(interpretedValue);
    // execute over normal operator
    SourceOperatorFactory scanProjectOperatorFactory = compileScanFilterProject(Optional.of(filterRowExpression), constant(true, BOOLEAN), compiler);
    boolean scanOperatorValue = executeFilter(scanProjectOperatorFactory, createNormalSplit(), session);
    results.add(scanOperatorValue);
    // execute over record set
    boolean recordValue = executeFilter(scanProjectOperatorFactory, createRecordSetSplit(), session);
    results.add(recordValue);
    // If the filter does not need bound values, execute query using full engine
    if (!needsBoundValue(filterExpression)) {
        MaterializedResult result = runner.execute("SELECT TRUE WHERE " + filter);
        assertEquals(result.getTypes().size(), 1);
        Boolean queryResult;
        if (result.getMaterializedRows().isEmpty()) {
            queryResult = false;
        } else {
            assertEquals(result.getMaterializedRows().size(), 1);
            queryResult = (Boolean) Iterables.getOnlyElement(result.getMaterializedRows()).getField(0);
        }
        results.add(queryResult);
    }
    return results;
}
Also used : Expression(io.prestosql.sql.tree.Expression) DereferenceExpression(io.prestosql.sql.tree.DereferenceExpression) RowExpression(io.prestosql.spi.relation.RowExpression) FilterAndProjectOperatorFactory(io.prestosql.operator.FilterAndProjectOperator.FilterAndProjectOperatorFactory) SourceOperatorFactory(io.prestosql.operator.SourceOperatorFactory) OperatorFactory(io.prestosql.operator.OperatorFactory) ArrayList(java.util.ArrayList) RowExpression(io.prestosql.spi.relation.RowExpression) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MaterializedResult(io.prestosql.testing.MaterializedResult) SourceOperatorFactory(io.prestosql.operator.SourceOperatorFactory)

Aggregations

OperatorFactory (io.prestosql.operator.OperatorFactory)36 PlanNodeId (io.prestosql.spi.plan.PlanNodeId)28 Type (io.prestosql.spi.type.Type)14 DriverContext (io.prestosql.operator.DriverContext)12 MaterializedResult (io.prestosql.testing.MaterializedResult)12 Test (org.testng.annotations.Test)11 DriverFactory (io.prestosql.operator.DriverFactory)9 SpatialIndexBuilderOperatorFactory (io.prestosql.operator.SpatialIndexBuilderOperator.SpatialIndexBuilderOperatorFactory)9 SpatialJoinOperatorFactory (io.prestosql.operator.SpatialJoinOperator.SpatialJoinOperatorFactory)9 Page (io.prestosql.spi.Page)9 PagesSpatialIndexFactory (io.prestosql.operator.PagesSpatialIndexFactory)7 ImmutableList (com.google.common.collect.ImmutableList)6 Metadata (io.prestosql.metadata.Metadata)6 SourceOperatorFactory (io.prestosql.operator.SourceOperatorFactory)6 TaskContext (io.prestosql.operator.TaskContext)6 ArrayList (java.util.ArrayList)6 RowPagesBuilder (io.prestosql.RowPagesBuilder)5 AggregationOperatorFactory (io.prestosql.operator.AggregationOperator.AggregationOperatorFactory)5 HashBuilderOperatorFactory (io.prestosql.operator.HashBuilderOperator.HashBuilderOperatorFactory)5 OperatorAssertion.toMaterializedResult (io.prestosql.operator.OperatorAssertion.toMaterializedResult)5