use of com.facebook.presto.spi.plan.PlanNodeId in project presto by prestodb.
the class TestDriver method testAbruptFinish.
private void testAbruptFinish(DriverContext driverContext) {
List<Type> types = ImmutableList.of(VARCHAR, BIGINT, BIGINT);
ValuesOperator source = new ValuesOperator(driverContext.addOperatorContext(0, new PlanNodeId("test"), "values"), rowPagesBuilder(types).addSequencePage(10, 20, 30, 40).build());
PageConsumerOperator sink = createSinkOperator(driverContext, types);
Driver driver = Driver.createDriver(driverContext, source, sink);
assertSame(driver.getDriverContext(), driverContext);
assertFalse(driver.isFinished());
driver.close();
assertTrue(driver.isFinished());
// finish is only called in normal operations
assertFalse(source.isFinished());
assertFalse(sink.isFinished());
// close is always called (values operator doesn't have a closed state)
assertTrue(sink.isClosed());
}
use of com.facebook.presto.spi.plan.PlanNodeId in project presto by prestodb.
the class TestDriver method testBrokenOperatorProcessWhileClosing.
private void testBrokenOperatorProcessWhileClosing(DriverContext driverContext) throws Exception {
BrokenOperator brokenOperator = new BrokenOperator(driverContext.addOperatorContext(0, new PlanNodeId("test"), "source"), true);
final Driver driver = Driver.createDriver(driverContext, brokenOperator, createSinkOperator(driverContext, ImmutableList.of()));
assertSame(driver.getDriverContext(), driverContext);
// block thread in operator close
Future<Boolean> driverClose = executor.submit(() -> {
driver.close();
return true;
});
brokenOperator.waitForLocked();
assertTrue(driver.processFor(new Duration(1, TimeUnit.MILLISECONDS)).isDone());
assertTrue(driver.isFinished());
brokenOperator.unlock();
assertTrue(driverClose.get());
}
use of com.facebook.presto.spi.plan.PlanNodeId in project presto by prestodb.
the class TestFilterAndProjectOperator method testMergeOutput.
@Test
public void testMergeOutput() {
List<Page> input = rowPagesBuilder(VARCHAR, BIGINT).addSequencePage(100, 0, 0).addSequencePage(100, 0, 0).addSequencePage(100, 0, 0).addSequencePage(100, 0, 0).build();
MetadataManager metadata = createTestMetadataManager();
RowExpression filter = call(EQUAL.name(), metadata.getFunctionAndTypeManager().resolveOperator(EQUAL, fromTypes(BIGINT, BIGINT)), BOOLEAN, field(1, BIGINT), constant(10L, BIGINT));
ExpressionCompiler compiler = new ExpressionCompiler(metadata, new PageFunctionCompiler(metadata, 0));
Supplier<PageProcessor> processor = compiler.compilePageProcessor(TEST_SESSION.getSqlFunctionProperties(), Optional.of(filter), ImmutableList.of(field(1, BIGINT)));
OperatorFactory operatorFactory = new FilterAndProjectOperator.FilterAndProjectOperatorFactory(0, new PlanNodeId("test"), processor, ImmutableList.of(BIGINT), new DataSize(64, KILOBYTE), 2);
List<Page> expected = rowPagesBuilder(BIGINT).row(10L).row(10L).row(10L).row(10L).build();
assertOperatorEquals(operatorFactory, ImmutableList.of(BIGINT), driverContext, input, expected);
}
use of com.facebook.presto.spi.plan.PlanNodeId in project presto by prestodb.
the class TestGroupIdOperator method testGroupId.
public void testGroupId() {
RowPagesBuilder rowPagesBuilder = rowPagesBuilder(false, ImmutableList.of(), BIGINT, VARCHAR, BOOLEAN, BIGINT);
List<Page> input = rowPagesBuilder.addSequencePage(3, 100, 400, 0, 1000).addSequencePage(3, 200, 500, 0, 1100).build();
GroupIdOperatorFactory operatorFactory = new GroupIdOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(VARCHAR, BOOLEAN, BIGINT, BIGINT, BIGINT), ImmutableList.of(ImmutableMap.of(0, 1, 1, 2, 3, 0), ImmutableMap.of(2, 3, 3, 0)));
MaterializedResult expected = resultBuilder(driverContext.getSession(), VARCHAR, BOOLEAN, BIGINT, BIGINT, BIGINT).row("400", true, null, 100L, 0L).row("401", false, null, 101L, 0L).row("402", true, null, 102L, 0L).row("500", true, null, 200L, 0L).row("501", false, null, 201L, 0L).row("502", true, null, 202L, 0L).row(null, null, 1000L, 100L, 1L).row(null, null, 1001L, 101L, 1L).row(null, null, 1002L, 102L, 1L).row(null, null, 1100L, 200L, 1L).row(null, null, 1101L, 201L, 1L).row(null, null, 1102L, 202L, 1L).build();
assertOperatorEqualsIgnoreOrder(operatorFactory, driverContext, input, expected);
}
use of com.facebook.presto.spi.plan.PlanNodeId in project presto by prestodb.
the class TestHashAggregationOperator method testMultiplePartialFlushes.
@Test(dataProvider = "hashEnabled")
public void testMultiplePartialFlushes(boolean hashEnabled) throws Exception {
List<Integer> hashChannels = Ints.asList(0);
RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, hashChannels, BIGINT);
List<Page> input = rowPagesBuilder.addSequencePage(500, 0).addSequencePage(500, 500).addSequencePage(500, 1000).addSequencePage(500, 1500).build();
HashAggregationOperatorFactory operatorFactory = new HashAggregationOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(BIGINT), hashChannels, ImmutableList.of(), Step.PARTIAL, ImmutableList.of(LONG_SUM.bind(ImmutableList.of(0), Optional.empty())), rowPagesBuilder.getHashChannel(), Optional.empty(), 100_000, Optional.of(new DataSize(1, KILOBYTE)), joinCompiler, true);
DriverContext driverContext = createDriverContext(1024);
try (Operator operator = operatorFactory.createOperator(driverContext)) {
List<Page> expectedPages = rowPagesBuilder(BIGINT, BIGINT).addSequencePage(2000, 0, 0).build();
MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, BIGINT).pages(expectedPages).build();
Iterator<Page> inputIterator = input.iterator();
// Fill up the aggregation
while (operator.needsInput() && inputIterator.hasNext()) {
operator.addInput(inputIterator.next());
}
assertThat(driverContext.getSystemMemoryUsage()).isGreaterThan(0);
assertEquals(driverContext.getMemoryUsage(), 0);
// Drain the output (partial flush)
List<Page> outputPages = new ArrayList<>();
while (true) {
Page output = operator.getOutput();
if (output == null) {
break;
}
outputPages.add(output);
}
// There should be some pages that were drained
assertTrue(!outputPages.isEmpty());
// The operator need input again since this was a partial flush
assertTrue(operator.needsInput());
// Now, drive the operator to completion
outputPages.addAll(toPages(operator, inputIterator));
MaterializedResult actual;
if (hashEnabled) {
// Drop the hashChannel for all pages
outputPages = dropChannel(outputPages, ImmutableList.of(1));
}
actual = toMaterializedResult(operator.getOperatorContext().getSession(), expected.getTypes(), outputPages);
assertEquals(actual.getTypes(), expected.getTypes());
assertEqualsIgnoreOrder(actual.getMaterializedRows(), expected.getMaterializedRows());
}
assertEquals(driverContext.getSystemMemoryUsage(), 0);
assertEquals(driverContext.getMemoryUsage(), 0);
}
Aggregations