Search in sources :

Example 1 with FixedPageSource

use of com.facebook.presto.spi.FixedPageSource in project presto by prestodb.

the class TestDriver method testBrokenOperatorAddSource.

@Test
public void testBrokenOperatorAddSource() throws Exception {
    PlanNodeId sourceId = new PlanNodeId("source");
    final List<Type> types = ImmutableList.of(VARCHAR, BIGINT, BIGINT);
    // create a table scan operator that does not block, which will cause the driver loop to busy wait
    TableScanOperator source = new NotBlockedTableScanOperator(driverContext.addOperatorContext(99, new PlanNodeId("test"), "values"), sourceId, new PageSourceProvider() {

        @Override
        public ConnectorPageSource createPageSource(Session session, Split split, List<ColumnHandle> columns) {
            return new FixedPageSource(rowPagesBuilder(types).addSequencePage(10, 20, 30, 40).build());
        }
    }, types, ImmutableList.of());
    BrokenOperator brokenOperator = new BrokenOperator(driverContext.addOperatorContext(0, new PlanNodeId("test"), "source"));
    final Driver driver = new Driver(driverContext, source, brokenOperator);
    // block thread in operator processing
    Future<Boolean> driverProcessFor = executor.submit(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return driver.processFor(new Duration(1, TimeUnit.MILLISECONDS)).isDone();
        }
    });
    brokenOperator.waitForLocked();
    assertSame(driver.getDriverContext(), driverContext);
    assertFalse(driver.isFinished());
    // processFor always returns NOT_BLOCKED, because DriveLockResult was not acquired
    assertTrue(driver.processFor(new Duration(1, TimeUnit.MILLISECONDS)).isDone());
    assertFalse(driver.isFinished());
    driver.updateSource(new TaskSource(sourceId, ImmutableSet.of(new ScheduledSplit(0, sourceId, newMockSplit())), true));
    assertFalse(driver.isFinished());
    // processFor always returns NOT_BLOCKED, because DriveLockResult was not acquired
    assertTrue(driver.processFor(new Duration(1, TimeUnit.SECONDS)).isDone());
    assertFalse(driver.isFinished());
    driver.close();
    assertTrue(driver.isFinished());
    try {
        driverProcessFor.get(1, TimeUnit.SECONDS);
        fail("Expected InterruptedException");
    } catch (ExecutionException e) {
        checkArgument(getRootCause(e) instanceof InterruptedException, "Expected root cause exception to be an instance of InterruptedException");
    }
}
Also used : PageSourceProvider(com.facebook.presto.split.PageSourceProvider) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ScheduledSplit(com.facebook.presto.ScheduledSplit) Duration(io.airlift.units.Duration) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource) FixedPageSource(com.facebook.presto.spi.FixedPageSource) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) Type(com.facebook.presto.spi.type.Type) ScheduledSplit(com.facebook.presto.ScheduledSplit) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) Split(com.facebook.presto.metadata.Split) ExecutionException(java.util.concurrent.ExecutionException) TaskSource(com.facebook.presto.TaskSource) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 2 with FixedPageSource

use of com.facebook.presto.spi.FixedPageSource in project presto by prestodb.

the class TestDriver method testAddSourceFinish.

@Test
public void testAddSourceFinish() {
    PlanNodeId sourceId = new PlanNodeId("source");
    final List<Type> types = ImmutableList.of(VARCHAR, BIGINT, BIGINT);
    TableScanOperator source = new TableScanOperator(driverContext.addOperatorContext(99, new PlanNodeId("test"), "values"), sourceId, new PageSourceProvider() {

        @Override
        public ConnectorPageSource createPageSource(Session session, Split split, List<ColumnHandle> columns) {
            return new FixedPageSource(rowPagesBuilder(types).addSequencePage(10, 20, 30, 40).build());
        }
    }, types, ImmutableList.of());
    PageConsumerOperator sink = createSinkOperator(source);
    Driver driver = new Driver(driverContext, source, sink);
    assertSame(driver.getDriverContext(), driverContext);
    assertFalse(driver.isFinished());
    assertFalse(driver.processFor(new Duration(1, TimeUnit.MILLISECONDS)).isDone());
    assertFalse(driver.isFinished());
    driver.updateSource(new TaskSource(sourceId, ImmutableSet.of(new ScheduledSplit(0, sourceId, newMockSplit())), true));
    assertFalse(driver.isFinished());
    assertTrue(driver.processFor(new Duration(1, TimeUnit.SECONDS)).isDone());
    assertTrue(driver.isFinished());
    assertTrue(sink.isFinished());
    assertTrue(source.isFinished());
}
Also used : PageSourceProvider(com.facebook.presto.split.PageSourceProvider) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ScheduledSplit(com.facebook.presto.ScheduledSplit) Duration(io.airlift.units.Duration) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource) FixedPageSource(com.facebook.presto.spi.FixedPageSource) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) PageConsumerOperator(com.facebook.presto.testing.PageConsumerOperator) Type(com.facebook.presto.spi.type.Type) ScheduledSplit(com.facebook.presto.ScheduledSplit) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) Split(com.facebook.presto.metadata.Split) TaskSource(com.facebook.presto.TaskSource) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 3 with FixedPageSource

use of com.facebook.presto.spi.FixedPageSource in project presto by prestodb.

the class TestScanFilterAndProjectOperator method testPageSource.

@Test
public void testPageSource() {
    final Page input = SequencePageBuilder.createSequencePage(ImmutableList.of(VARCHAR), 10_000, 0);
    DriverContext driverContext = newDriverContext();
    List<RowExpression> projections = ImmutableList.of(field(0, VARCHAR));
    Supplier<CursorProcessor> cursorProcessor = expressionCompiler.compileCursorProcessor(driverContext.getSession().getSqlFunctionProperties(), Optional.empty(), projections, "key");
    Supplier<PageProcessor> pageProcessor = expressionCompiler.compilePageProcessor(driverContext.getSession().getSqlFunctionProperties(), Optional.empty(), projections);
    ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory factory = new ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory(0, new PlanNodeId("test"), new PlanNodeId("0"), (session, split, table, columns) -> new FixedPageSource(ImmutableList.of(input)), cursorProcessor, pageProcessor, TESTING_TABLE_HANDLE, ImmutableList.of(), ImmutableList.of(VARCHAR), Optional.empty(), new DataSize(0, BYTE), 0);
    SourceOperator operator = factory.createOperator(driverContext);
    operator.addSplit(new Split(new ConnectorId("test"), TestingTransactionHandle.create(), TestingSplit.createLocalSplit()));
    operator.noMoreSplits();
    MaterializedResult expected = toMaterializedResult(driverContext.getSession(), ImmutableList.of(VARCHAR), ImmutableList.of(input));
    MaterializedResult actual = toMaterializedResult(driverContext.getSession(), ImmutableList.of(VARCHAR), toPages(operator));
    assertEquals(actual.getRowCount(), expected.getRowCount());
    assertEquals(actual, expected);
}
Also used : CursorProcessor(com.facebook.presto.operator.project.CursorProcessor) RowExpression(com.facebook.presto.spi.relation.RowExpression) Page(com.facebook.presto.common.Page) FixedPageSource(com.facebook.presto.spi.FixedPageSource) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PageProcessor(com.facebook.presto.operator.project.PageProcessor) DataSize(io.airlift.units.DataSize) TestingSplit(com.facebook.presto.testing.TestingSplit) Split(com.facebook.presto.metadata.Split) OperatorAssertion.toMaterializedResult(com.facebook.presto.operator.OperatorAssertion.toMaterializedResult) MaterializedResult(com.facebook.presto.testing.MaterializedResult) ConnectorId(com.facebook.presto.spi.ConnectorId) Test(org.testng.annotations.Test)

Example 4 with FixedPageSource

use of com.facebook.presto.spi.FixedPageSource in project presto by prestodb.

the class TestDriver method testMemoryRevocationRace.

private void testMemoryRevocationRace(DriverContext driverContext) {
    List<Type> types = ImmutableList.of(VARCHAR, BIGINT, BIGINT);
    TableScanOperator source = new AlwaysBlockedMemoryRevokingTableScanOperator(driverContext.addOperatorContext(99, new PlanNodeId("test"), "scan"), new PlanNodeId("source"), (session, split, table, columns) -> new FixedPageSource(rowPagesBuilder(types).addSequencePage(10, 20, 30, 40).build()), TESTING_TABLE_HANDLE, ImmutableList.of());
    Driver driver = Driver.createDriver(driverContext, source, createSinkOperator(driverContext, types));
    // the table scan operator will request memory revocation with requestMemoryRevoking()
    // while the driver is still not done with the processFor() method and before it moves to
    // updateDriverBlockedFuture() method.
    assertTrue(driver.processFor(new Duration(100, TimeUnit.MILLISECONDS)).isDone());
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) Type(com.facebook.presto.common.type.Type) Duration(io.airlift.units.Duration) FixedPageSource(com.facebook.presto.spi.FixedPageSource)

Example 5 with FixedPageSource

use of com.facebook.presto.spi.FixedPageSource in project presto by prestodb.

the class NodesSystemTable method pageSource.

@Override
public ConnectorPageSource pageSource(ConnectorTransactionHandle transaction, ConnectorSession session, TupleDomain<Integer> constraint) {
    Set<ElasticsearchNode> nodes = client.getNodes();
    BlockBuilder nodeId = VARCHAR.createBlockBuilder(null, nodes.size());
    BlockBuilder prestoAddress = VARCHAR.createBlockBuilder(null, nodes.size());
    BlockBuilder elasticsearchNodeId = VARCHAR.createBlockBuilder(null, nodes.size());
    BlockBuilder elasticsearchAddress = VARCHAR.createBlockBuilder(null, nodes.size());
    for (ElasticsearchNode node : nodes) {
        VARCHAR.writeString(nodeId, currentNode.getNodeIdentifier());
        VARCHAR.writeString(prestoAddress, currentNode.getHostAndPort().toString());
        VARCHAR.writeString(elasticsearchNodeId, node.getId());
        if (node.getAddress().isPresent()) {
            VARCHAR.writeString(elasticsearchAddress, node.getAddress().get());
        } else {
            elasticsearchAddress.appendNull();
        }
    }
    return new FixedPageSource(ImmutableList.of(new Page(nodeId.build(), prestoAddress.build(), elasticsearchNodeId.build(), elasticsearchAddress.build())));
}
Also used : ElasticsearchNode(com.facebook.presto.elasticsearch.client.ElasticsearchNode) Page(com.facebook.presto.common.Page) FixedPageSource(com.facebook.presto.spi.FixedPageSource) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Aggregations

FixedPageSource (com.facebook.presto.spi.FixedPageSource)15 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)8 Split (com.facebook.presto.metadata.Split)7 Duration (io.airlift.units.Duration)7 Type (com.facebook.presto.common.type.Type)6 Test (org.testng.annotations.Test)6 Page (com.facebook.presto.common.Page)5 ColumnHandle (com.facebook.presto.spi.ColumnHandle)5 ScheduledSplit (com.facebook.presto.execution.ScheduledSplit)4 TaskSource (com.facebook.presto.execution.TaskSource)4 ConnectorId (com.facebook.presto.spi.ConnectorId)4 PageConsumerOperator (com.facebook.presto.testing.PageConsumerOperator)4 CursorProcessor (com.facebook.presto.operator.project.CursorProcessor)3 PageProcessor (com.facebook.presto.operator.project.PageProcessor)3 RowExpression (com.facebook.presto.spi.relation.RowExpression)3 TestingSplit (com.facebook.presto.testing.TestingSplit)3 ImmutableList (com.google.common.collect.ImmutableList)3 DataSize (io.airlift.units.DataSize)3 ScheduledSplit (com.facebook.presto.ScheduledSplit)2 Session (com.facebook.presto.Session)2