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