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);
}
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);
}
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);
}
}
}
}
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);
}
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;
}
Aggregations