Search in sources :

Example 6 with FixedPageSource

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

the class InformationSchemaPageSourceProvider method createPageSource.

@Override
public ConnectorPageSource createPageSource(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorSplit split, List<ColumnHandle> columns, SplitContext splitContext) {
    InternalTable table = getInternalTable(session, split, columns);
    List<Integer> channels = new ArrayList<>();
    for (ColumnHandle column : columns) {
        String columnName = ((InformationSchemaColumnHandle) column).getColumnName();
        int columnIndex = table.getColumnIndex(columnName);
        channels.add(columnIndex);
    }
    ImmutableList.Builder<Page> pages = ImmutableList.builder();
    for (Page page : table.getPages()) {
        Block[] blocks = new Block[channels.size()];
        for (int index = 0; index < blocks.length; index++) {
            blocks[index] = page.getBlock(channels.get(index));
        }
        pages.add(new Page(page.getPositionCount(), blocks));
    }
    return new FixedPageSource(pages.build());
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) Page(com.facebook.presto.common.Page) InternalTable(com.facebook.presto.metadata.InternalTable) FixedPageSource(com.facebook.presto.spi.FixedPageSource) Block(com.facebook.presto.common.block.Block)

Example 7 with FixedPageSource

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

the class InformationSchemaPageSourceProvider method createPageSource.

@Override
public ConnectorPageSource createPageSource(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorSplit split, List<ColumnHandle> columns) {
    InternalTable table = getInternalTable(transactionHandle, session, split, columns);
    List<Integer> channels = new ArrayList<>();
    for (ColumnHandle column : columns) {
        String columnName = ((InformationSchemaColumnHandle) column).getColumnName();
        int columnIndex = table.getColumnIndex(columnName);
        channels.add(columnIndex);
    }
    ImmutableList.Builder<Page> pages = ImmutableList.builder();
    for (Page page : table.getPages()) {
        Block[] blocks = new Block[channels.size()];
        for (int index = 0; index < blocks.length; index++) {
            blocks[index] = page.getBlock(channels.get(index));
        }
        pages.add(new Page(page.getPositionCount(), blocks));
    }
    return new FixedPageSource(pages.build());
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) Page(com.facebook.presto.spi.Page) InternalTable(com.facebook.presto.metadata.InternalTable) FixedPageSource(com.facebook.presto.spi.FixedPageSource) Constraint(com.facebook.presto.spi.Constraint) Block(com.facebook.presto.spi.block.Block)

Example 8 with FixedPageSource

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

the class PageSourceManager method createPageSource.

@Override
public ConnectorPageSource createPageSource(Session session, Split split, TableHandle table, List<ColumnHandle> columns) {
    requireNonNull(split, "split is null");
    requireNonNull(columns, "columns is null");
    Optional<Supplier<TupleDomain<ColumnHandle>>> dynamicFilter = table.getDynamicFilter();
    // directly return the result if the given constraint is always false
    if (dynamicFilter.isPresent() && dynamicFilter.get().get().isNone()) {
        return new FixedPageSource(ImmutableList.of());
    }
    if (dynamicFilter.isPresent()) {
        split = new Split(split.getConnectorId(), split.getTransactionHandle(), split.getConnectorSplit(), split.getLifespan(), new SplitContext(split.getSplitContext().isCacheable(), dynamicFilter.get().get()));
    }
    ConnectorSession connectorSession = session.toConnectorSession(split.getConnectorId());
    if (table.getLayout().isPresent()) {
        return getPageSourceProvider(split).createPageSource(split.getTransactionHandle(), connectorSession, split.getConnectorSplit(), table.getLayout().get(), columns, split.getSplitContext());
    }
    return getPageSourceProvider(split).createPageSource(split.getTransactionHandle(), connectorSession, split.getConnectorSplit(), columns, split.getSplitContext());
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) SplitContext(com.facebook.presto.spi.SplitContext) Supplier(java.util.function.Supplier) ConnectorSession(com.facebook.presto.spi.ConnectorSession) Split(com.facebook.presto.metadata.Split) FixedPageSource(com.facebook.presto.spi.FixedPageSource)

Example 9 with FixedPageSource

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

the class TestDriver method testBrokenOperatorAddSource.

private void testBrokenOperatorAddSource(DriverContext driverContext) 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, (session, split, table, columns) -> new FixedPageSource(rowPagesBuilder(types).addSequencePage(10, 20, 30, 40).build()), TESTING_TABLE_HANDLE, ImmutableList.of());
    BrokenOperator brokenOperator = new BrokenOperator(driverContext.addOperatorContext(0, new PlanNodeId("test"), "source"));
    final Driver driver = Driver.createDriver(driverContext, source, brokenOperator);
    // block thread in operator processing
    Future<Boolean> driverProcessFor = executor.submit(() -> 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) {
        assertDriverInterrupted(e.getCause());
    }
}
Also used : ScheduledSplit(com.facebook.presto.execution.ScheduledSplit) Duration(io.airlift.units.Duration) FixedPageSource(com.facebook.presto.spi.FixedPageSource) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) Type(com.facebook.presto.common.type.Type) ExecutionException(java.util.concurrent.ExecutionException) TaskSource(com.facebook.presto.execution.TaskSource)

Example 10 with FixedPageSource

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

the class TestDriver method testAddSourceFinish.

private void testAddSourceFinish(DriverContext driverContext) {
    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, (session, split, table, columns) -> new FixedPageSource(rowPagesBuilder(types).addSequencePage(10, 20, 30, 40).build()), TESTING_TABLE_HANDLE, ImmutableList.of());
    PageConsumerOperator sink = createSinkOperator(driverContext, types);
    Driver driver = Driver.createDriver(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 : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PageConsumerOperator(com.facebook.presto.testing.PageConsumerOperator) Type(com.facebook.presto.common.type.Type) ScheduledSplit(com.facebook.presto.execution.ScheduledSplit) Duration(io.airlift.units.Duration) FixedPageSource(com.facebook.presto.spi.FixedPageSource) TaskSource(com.facebook.presto.execution.TaskSource)

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