use of com.facebook.presto.spi.ConnectorPageSource in project presto by prestodb.
the class TestHiveFileFormats method testCursorProvider.
private void testCursorProvider(HiveRecordCursorProvider cursorProvider, FileSplit split, HiveStorageFormat storageFormat, List<TestColumn> testColumns, ConnectorSession session, int rowCount) {
List<HivePartitionKey> partitionKeys = testColumns.stream().filter(TestColumn::isPartitionKey).map(TestColumn::toHivePartitionKey).collect(toList());
List<HiveColumnHandle> partitionKeyColumnHandles = getColumnHandles(testColumns.stream().filter(TestColumn::isPartitionKey).collect(toImmutableList()));
List<Column> tableDataColumns = testColumns.stream().filter(column -> !column.isPartitionKey()).map(column -> new Column(column.getName(), HiveType.valueOf(column.getType()), Optional.empty(), Optional.empty())).collect(toImmutableList());
Configuration configuration = new Configuration();
configuration.set("io.compression.codecs", LzoCodec.class.getName() + "," + LzopCodec.class.getName());
Optional<ConnectorPageSource> pageSource = HivePageSourceProvider.createHivePageSource(ImmutableSet.of(cursorProvider), ImmutableSet.of(), configuration, session, split.getPath(), OptionalInt.empty(), split.getStart(), split.getLength(), split.getLength(), Instant.now().toEpochMilli(), new Storage(StorageFormat.create(storageFormat.getSerDe(), storageFormat.getInputFormat(), storageFormat.getOutputFormat()), "location", Optional.empty(), false, ImmutableMap.of(), ImmutableMap.of()), TupleDomain.all(), getColumnHandles(testColumns), ImmutableMap.of(), partitionKeys, DateTimeZone.getDefault(), FUNCTION_AND_TYPE_MANAGER, new SchemaTableName("schema", "table"), partitionKeyColumnHandles, tableDataColumns, ImmutableMap.of(), tableDataColumns.size(), TableToPartitionMapping.empty(), Optional.empty(), false, DEFAULT_HIVE_FILE_CONTEXT, TRUE_CONSTANT, false, ROW_EXPRESSION_SERVICE, Optional.empty(), ImmutableMap.of());
RecordCursor cursor = ((RecordPageSource) pageSource.get()).getCursor();
checkCursor(cursor, testColumns, rowCount);
}
use of com.facebook.presto.spi.ConnectorPageSource in project presto by prestodb.
the class ThriftTpchService method getRowsSync.
private PrestoThriftPageResult getRowsSync(PrestoThriftId splitId, List<String> outputColumns, long maxBytes, PrestoThriftNullableToken nextToken) {
SplitInfo splitInfo = SPLIT_INFO_CODEC.fromJson(splitId.getId());
checkArgument(maxBytes >= DEFAULT_MAX_PAGE_SIZE_IN_BYTES, "requested maxBytes is too small");
ConnectorPageSource pageSource;
if (!splitInfo.isIndexSplit()) {
// normal scan
pageSource = createPageSource(splitInfo, outputColumns);
} else {
// index lookup
pageSource = createLookupPageSource(splitInfo, outputColumns);
}
return getRowsInternal(pageSource, splitInfo.getTableName(), outputColumns, nextToken.getToken());
}
use of com.facebook.presto.spi.ConnectorPageSource in project presto by prestodb.
the class ShardCompactor method compactSorted.
public List<ShardInfo> compactSorted(long transactionId, boolean tableSupportsDeltaDelete, OptionalInt bucketNumber, Map<UUID, Optional<UUID>> uuidsMap, List<ColumnInfo> columns, List<Long> sortColumnIds, List<SortOrder> sortOrders) throws IOException {
checkArgument(sortColumnIds.size() == sortOrders.size(), "sortColumnIds and sortOrders must be of the same size");
long start = System.nanoTime();
List<Long> columnIds = columns.stream().map(ColumnInfo::getColumnId).collect(toList());
List<Type> columnTypes = columns.stream().map(ColumnInfo::getType).collect(toList());
checkArgument(columnIds.containsAll(sortColumnIds), "sortColumnIds must be a subset of columnIds");
List<Integer> sortIndexes = sortColumnIds.stream().map(columnIds::indexOf).collect(toList());
Queue<SortedPageSource> rowSources = new PriorityQueue<>();
StoragePageSink outputPageSink = storageManager.createStoragePageSink(DEFAULT_RAPTOR_CONTEXT, transactionId, bucketNumber, columnIds, columnTypes, false);
try {
uuidsMap.forEach((uuid, deltaUuid) -> {
ConnectorPageSource pageSource = storageManager.getPageSource(DEFAULT_RAPTOR_CONTEXT, DEFAULT_HIVE_FILE_CONTEXT, uuid, deltaUuid, tableSupportsDeltaDelete, bucketNumber, columnIds, columnTypes, TupleDomain.all(), readerAttributes);
SortedPageSource rowSource = new SortedPageSource(pageSource, columnTypes, sortIndexes, sortOrders);
rowSources.add(rowSource);
});
while (!rowSources.isEmpty()) {
SortedPageSource rowSource = rowSources.poll();
if (!rowSource.hasNext()) {
// rowSource is empty, close it
rowSource.close();
continue;
}
outputPageSink.appendPages(ImmutableList.of(rowSource.next()));
if (outputPageSink.isFull()) {
outputPageSink.flush();
}
rowSources.add(rowSource);
}
outputPageSink.flush();
List<ShardInfo> shardInfos = getFutureValue(outputPageSink.commit());
int deltaCount = uuidsMap.values().stream().filter(Optional::isPresent).collect(toSet()).size();
updateStats(uuidsMap.size(), deltaCount, shardInfos.size(), nanosSince(start).toMillis());
return shardInfos;
} catch (IOException | RuntimeException e) {
outputPageSink.rollback();
throw e;
} finally {
rowSources.forEach(SortedPageSource::closeQuietly);
}
}
use of com.facebook.presto.spi.ConnectorPageSource in project presto by prestodb.
the class TestShardCompactor method getPages.
private List<Page> getPages(StorageManager storageManager, Set<UUID> uuids, List<Long> columnIds, List<Type> columnTypes) throws IOException {
ImmutableList.Builder<Page> pages = ImmutableList.builder();
for (UUID uuid : uuids) {
try (ConnectorPageSource pageSource = getPageSource(storageManager, columnIds, columnTypes, uuid, Optional.empty(), false)) {
while (!pageSource.isFinished()) {
Page outputPage = pageSource.getNextPage();
if (outputPage == null) {
break;
}
pages.add(outputPage.getLoadedPage());
}
}
}
return pages.build();
}
use of com.facebook.presto.spi.ConnectorPageSource in project presto by prestodb.
the class TestShardCompactor method getMaterializedRows.
private MaterializedResult getMaterializedRows(StorageManager storageManager, List<UUID> uuids, List<Long> columnIds, List<Type> columnTypes) throws IOException {
MaterializedResult.Builder rows = MaterializedResult.resultBuilder(SESSION, columnTypes);
for (UUID uuid : uuids) {
try (ConnectorPageSource pageSource = getPageSource(storageManager, columnIds, columnTypes, uuid, Optional.empty(), false)) {
MaterializedResult result = materializeSourceDataStream(SESSION, pageSource, columnTypes);
rows.rows(result.getMaterializedRows());
}
}
return rows.build();
}
Aggregations