use of com.facebook.presto.spi.ConnectorPageSource in project presto by prestodb.
the class TestOrcPageSourceMemoryTracking method testPageSource.
@Test
public void testPageSource() throws Exception {
// Numbers used in assertions in this test may change when implementation is modified,
// feel free to change them if they break in the future
ConnectorPageSource pageSource = testPreparer.newPageSource();
assertEquals(pageSource.getSystemMemoryUsage(), 0);
long memoryUsage = -1;
for (int i = 0; i < 20; i++) {
assertFalse(pageSource.isFinished());
Page page = pageSource.getNextPage();
assertNotNull(page);
Block block = page.getBlock(1);
if (memoryUsage == -1) {
// Memory usage before lazy-loading the block
assertBetweenInclusive(pageSource.getSystemMemoryUsage(), 180000L, 189999L);
// trigger loading for lazy block
createUnboundedVarcharType().getSlice(block, block.getPositionCount() - 1);
memoryUsage = pageSource.getSystemMemoryUsage();
// Memory usage after lazy-loading the actual block
assertBetweenInclusive(memoryUsage, 460000L, 469999L);
} else {
assertEquals(pageSource.getSystemMemoryUsage(), memoryUsage);
// trigger loading for lazy block
createUnboundedVarcharType().getSlice(block, block.getPositionCount() - 1);
assertEquals(pageSource.getSystemMemoryUsage(), memoryUsage);
}
}
memoryUsage = -1;
for (int i = 20; i < 40; i++) {
assertFalse(pageSource.isFinished());
Page page = pageSource.getNextPage();
assertNotNull(page);
Block block = page.getBlock(1);
if (memoryUsage == -1) {
// Memory usage before lazy-loading the block
assertBetweenInclusive(pageSource.getSystemMemoryUsage(), 180000L, 189999L);
// trigger loading for lazy block
createUnboundedVarcharType().getSlice(block, block.getPositionCount() - 1);
memoryUsage = pageSource.getSystemMemoryUsage();
// Memory usage after lazy-loading the actual block
assertBetweenInclusive(memoryUsage, 460000L, 469999L);
} else {
assertEquals(pageSource.getSystemMemoryUsage(), memoryUsage);
// trigger loading for lazy block
createUnboundedVarcharType().getSlice(block, block.getPositionCount() - 1);
assertEquals(pageSource.getSystemMemoryUsage(), memoryUsage);
}
}
memoryUsage = -1;
for (int i = 40; i < 50; i++) {
assertFalse(pageSource.isFinished());
Page page = pageSource.getNextPage();
assertNotNull(page);
Block block = page.getBlock(1);
if (memoryUsage == -1) {
// Memory usage before lazy-loading the block
assertBetweenInclusive(pageSource.getSystemMemoryUsage(), 90000L, 99999L);
// trigger loading for lazy block
createUnboundedVarcharType().getSlice(block, block.getPositionCount() - 1);
memoryUsage = pageSource.getSystemMemoryUsage();
// Memory usage after lazy-loading the actual block
assertBetweenInclusive(memoryUsage, 360000L, 369999L);
} else {
assertEquals(pageSource.getSystemMemoryUsage(), memoryUsage);
// trigger loading for lazy block
createUnboundedVarcharType().getSlice(block, block.getPositionCount() - 1);
assertEquals(pageSource.getSystemMemoryUsage(), memoryUsage);
}
}
assertFalse(pageSource.isFinished());
assertNull(pageSource.getNextPage());
assertTrue(pageSource.isFinished());
assertEquals(pageSource.getSystemMemoryUsage(), 0);
pageSource.close();
}
use of com.facebook.presto.spi.ConnectorPageSource in project presto by prestodb.
the class AbstractTestHiveClient method testTypesRcTextRecordCursor.
@Test
public void testTypesRcTextRecordCursor() throws Exception {
try (Transaction transaction = newTransaction()) {
ConnectorSession session = newSession();
ConnectorMetadata metadata = transaction.getMetadata();
if (metadata.getTableHandle(session, new SchemaTableName(database, "presto_test_types_rctext")) == null) {
return;
}
ConnectorTableHandle tableHandle = getTableHandle(metadata, new SchemaTableName(database, "presto_test_types_rctext"));
ConnectorTableMetadata tableMetadata = metadata.getTableMetadata(session, tableHandle);
HiveSplit hiveSplit = getHiveSplit(tableHandle);
List<ColumnHandle> columnHandles = ImmutableList.copyOf(metadata.getColumnHandles(session, tableHandle).values());
ConnectorPageSourceProvider pageSourceProvider = new HivePageSourceProvider(new HiveClientConfig().setTimeZone(timeZone.getID()), hdfsEnvironment, ImmutableSet.of(new ColumnarTextHiveRecordCursorProvider(hdfsEnvironment)), ImmutableSet.of(), TYPE_MANAGER);
ConnectorPageSource pageSource = pageSourceProvider.createPageSource(transaction.getTransactionHandle(), session, hiveSplit, columnHandles);
assertGetRecords(RCTEXT, tableMetadata, hiveSplit, pageSource, columnHandles);
}
}
use of com.facebook.presto.spi.ConnectorPageSource in project presto by prestodb.
the class AbstractTestHiveClient method readTable.
private MaterializedResult readTable(Transaction transaction, ConnectorTableHandle tableHandle, List<ColumnHandle> columnHandles, ConnectorSession session, TupleDomain<ColumnHandle> tupleDomain, OptionalInt expectedSplitCount, Optional<HiveStorageFormat> expectedStorageFormat) throws Exception {
List<ConnectorTableLayoutResult> tableLayoutResults = transaction.getMetadata().getTableLayouts(session, tableHandle, new Constraint<>(tupleDomain, bindings -> true), Optional.empty());
ConnectorTableLayoutHandle layoutHandle = getOnlyElement(tableLayoutResults).getTableLayout().getHandle();
List<ConnectorSplit> splits = getAllSplits(splitManager.getSplits(transaction.getTransactionHandle(), session, layoutHandle));
if (expectedSplitCount.isPresent()) {
assertEquals(splits.size(), expectedSplitCount.getAsInt());
}
ImmutableList.Builder<MaterializedRow> allRows = ImmutableList.builder();
for (ConnectorSplit split : splits) {
try (ConnectorPageSource pageSource = pageSourceProvider.createPageSource(transaction.getTransactionHandle(), session, split, columnHandles)) {
if (expectedStorageFormat.isPresent()) {
assertPageSourceType(pageSource, expectedStorageFormat.get());
}
MaterializedResult result = materializeSourceDataStream(session, pageSource, getTypes(columnHandles));
allRows.addAll(result.getMaterializedRows());
}
}
return new MaterializedResult(allRows.build(), getTypes(columnHandles));
}
use of com.facebook.presto.spi.ConnectorPageSource in project presto by prestodb.
the class AbstractTestHiveClientS3 method testGetRecordsS3.
@Test
public void testGetRecordsS3() throws Exception {
try (Transaction transaction = newTransaction()) {
ConnectorMetadata metadata = transaction.getMetadata();
ConnectorSession session = newSession();
ConnectorTableHandle table = getTableHandle(metadata, tableS3);
List<ColumnHandle> columnHandles = ImmutableList.copyOf(metadata.getColumnHandles(session, table).values());
Map<String, Integer> columnIndex = indexColumns(columnHandles);
List<ConnectorTableLayoutResult> tableLayoutResults = metadata.getTableLayouts(session, table, new Constraint<>(TupleDomain.all(), bindings -> true), Optional.empty());
HiveTableLayoutHandle layoutHandle = (HiveTableLayoutHandle) getOnlyElement(tableLayoutResults).getTableLayout().getHandle();
assertEquals(layoutHandle.getPartitions().get().size(), 1);
ConnectorSplitSource splitSource = splitManager.getSplits(transaction.getTransactionHandle(), session, layoutHandle);
long sum = 0;
for (ConnectorSplit split : getAllSplits(splitSource)) {
try (ConnectorPageSource pageSource = pageSourceProvider.createPageSource(transaction.getTransactionHandle(), session, split, columnHandles)) {
MaterializedResult result = materializeSourceDataStream(session, pageSource, getTypes(columnHandles));
for (MaterializedRow row : result) {
sum += (Long) row.getField(columnIndex.get("t_bigint"));
}
}
}
assertEquals(sum, 78300);
}
}
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, int rowCount) throws IOException {
Properties splitProperties = new Properties();
splitProperties.setProperty(FILE_INPUT_FORMAT, storageFormat.getInputFormat());
splitProperties.setProperty(SERIALIZATION_LIB, storageFormat.getSerDe());
splitProperties.setProperty("columns", Joiner.on(',').join(transform(filter(testColumns, not(TestColumn::isPartitionKey)), TestColumn::getName)));
splitProperties.setProperty("columns.types", Joiner.on(',').join(transform(filter(testColumns, not(TestColumn::isPartitionKey)), TestColumn::getType)));
List<HivePartitionKey> partitionKeys = testColumns.stream().filter(TestColumn::isPartitionKey).map(input -> new HivePartitionKey(input.getName(), HiveType.valueOf(input.getObjectInspector().getTypeName()), (String) input.getWriteValue())).collect(toList());
Optional<ConnectorPageSource> pageSource = HivePageSourceProvider.createHivePageSource(ImmutableSet.of(cursorProvider), ImmutableSet.of(), "test", new Configuration(), SESSION, split.getPath(), OptionalInt.empty(), split.getStart(), split.getLength(), splitProperties, TupleDomain.all(), getColumnHandles(testColumns), partitionKeys, DateTimeZone.getDefault(), TYPE_MANAGER, ImmutableMap.of());
RecordCursor cursor = ((RecordPageSource) pageSource.get()).getCursor();
checkCursor(cursor, testColumns, rowCount);
}
Aggregations