use of com.facebook.presto.common.Page in project presto by prestodb.
the class TestGroupByHash method testContainsMultipleColumns.
@Test
public void testContainsMultipleColumns() {
Block valuesBlock = BlockAssertions.createDoubleSequenceBlock(0, 10);
Block stringValuesBlock = BlockAssertions.createStringSequenceBlock(0, 10);
Block hashBlock = TypeUtils.getHashBlock(ImmutableList.of(DOUBLE, VARCHAR), valuesBlock, stringValuesBlock);
int[] hashChannels = { 0, 1 };
GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(DOUBLE, VARCHAR), hashChannels, Optional.of(2), 100, JOIN_COMPILER);
groupByHash.getGroupIds(new Page(valuesBlock, stringValuesBlock, hashBlock)).process();
Block testValuesBlock = BlockAssertions.createDoublesBlock((double) 3);
Block testStringValuesBlock = BlockAssertions.createStringsBlock("3");
Block testHashBlock = TypeUtils.getHashBlock(ImmutableList.of(DOUBLE, VARCHAR), testValuesBlock, testStringValuesBlock);
assertTrue(groupByHash.contains(0, new Page(testValuesBlock, testStringValuesBlock, testHashBlock), hashChannels));
}
use of com.facebook.presto.common.Page in project presto by prestodb.
the class TestGroupByHash method testMemoryReservationYield.
@Test(dataProvider = "dataType")
public void testMemoryReservationYield(Type type) {
// Create a page with positionCount >> expected size of groupByHash
int length = 1_000_000;
Block valuesBlock;
if (type == VARCHAR) {
valuesBlock = createStringSequenceBlock(0, length);
} else if (type == BIGINT) {
valuesBlock = createLongSequenceBlock(0, length);
} else {
throw new IllegalArgumentException("unsupported data type");
}
Block hashBlock = getHashBlock(ImmutableList.of(type), valuesBlock);
Page page = new Page(valuesBlock, hashBlock);
AtomicInteger currentQuota = new AtomicInteger(0);
AtomicInteger allowedQuota = new AtomicInteger(3);
UpdateMemory updateMemory = () -> {
if (currentQuota.get() < allowedQuota.get()) {
currentQuota.getAndIncrement();
return true;
}
return false;
};
int yields = 0;
// test addPage
GroupByHash groupByHash = createGroupByHash(ImmutableList.of(type), new int[] { 0 }, Optional.of(1), 1, false, JOIN_COMPILER, updateMemory);
boolean finish = false;
Work<?> addPageWork = groupByHash.addPage(page);
while (!finish) {
finish = addPageWork.process();
if (!finish) {
assertEquals(currentQuota.get(), allowedQuota.get());
// assert if we are blocked, we are going to be blocked again without changing allowedQuota
assertFalse(addPageWork.process());
assertEquals(currentQuota.get(), allowedQuota.get());
yields++;
allowedQuota.getAndAdd(3);
}
}
// assert there is not anything missing
assertEquals(length, groupByHash.getGroupCount());
// assert we yield for every 3 rehashes
// currentQuota is essentially the count we have successfully rehashed
// the rehash count is 20 = log(1_000_000 / 0.75)
assertEquals(currentQuota.get(), 20);
assertEquals(currentQuota.get() / 3, yields);
// test getGroupIds
currentQuota.set(0);
allowedQuota.set(3);
yields = 0;
groupByHash = createGroupByHash(ImmutableList.of(type), new int[] { 0 }, Optional.of(1), 1, false, JOIN_COMPILER, updateMemory);
finish = false;
Work<GroupByIdBlock> getGroupIdsWork = groupByHash.getGroupIds(page);
while (!finish) {
finish = getGroupIdsWork.process();
if (!finish) {
assertEquals(currentQuota.get(), allowedQuota.get());
// assert if we are blocked, we are going to be blocked again without changing allowedQuota
assertFalse(getGroupIdsWork.process());
assertEquals(currentQuota.get(), allowedQuota.get());
yields++;
allowedQuota.getAndAdd(3);
}
}
// assert there is not anything missing
assertEquals(length, groupByHash.getGroupCount());
assertEquals(length, getGroupIdsWork.getResult().getPositionCount());
// assert we yield for every 3 rehashes
// currentQuota is essentially the count we have successfully rehashed
// the rehash count is 20 = log2(1_000_000 / 0.75)
assertEquals(currentQuota.get(), 20);
assertEquals(currentQuota.get() / 3, yields);
}
use of com.facebook.presto.common.Page in project presto by prestodb.
the class BenchmarkGroupedTopNBuilder method topNToList.
public List<Page> topNToList(BenchmarkData data) {
GroupedTopNBuilder topNBuilder = data.getTopNBuilder();
for (Page page : data.getPages()) {
Work<?> work = topNBuilder.processPage(page);
boolean finished;
do {
finished = work.process();
} while (!finished);
}
return ImmutableList.copyOf(topNBuilder.buildResult());
}
use of com.facebook.presto.common.Page in project presto by prestodb.
the class BenchmarkGroupedTopNBuilder method topN.
@Benchmark
public void topN(BenchmarkData data, Blackhole blackhole) {
GroupedTopNBuilder topNBuilder = data.getTopNBuilder();
for (Page page : data.getPages()) {
Work<?> work = topNBuilder.processPage(page);
boolean finished;
do {
finished = work.process();
} while (!finished);
}
Iterator<Page> results = topNBuilder.buildResult();
while (results.hasNext()) {
blackhole.consume(results.next());
}
}
use of com.facebook.presto.common.Page in project presto by prestodb.
the class BenchmarkGroupedTopNBuilder method createInputPages.
private static List<Page> createInputPages(int positions, List<Type> types, int positionsPerPage, int groupCount, int seed) {
Random random = new Random(seed);
List<Page> pages = new ArrayList<>();
PageBuilder pageBuilder = new PageBuilder(types);
LineItemGenerator lineItemGenerator = new LineItemGenerator(1, 1, 1);
Iterator<LineItem> iterator = lineItemGenerator.iterator();
for (int i = 0; i < positions; i++) {
pageBuilder.declarePosition();
LineItem lineItem = iterator.next();
BIGINT.writeLong(pageBuilder.getBlockBuilder(HASH_GROUP), groupCount > 1 ? random.nextInt(groupCount) : 1);
DOUBLE.writeDouble(pageBuilder.getBlockBuilder(EXTENDED_PRICE), lineItem.getExtendedPrice());
DOUBLE.writeDouble(pageBuilder.getBlockBuilder(DISCOUNT), lineItem.getDiscount());
DATE.writeLong(pageBuilder.getBlockBuilder(SHIP_DATE), lineItem.getShipDate());
DOUBLE.writeDouble(pageBuilder.getBlockBuilder(QUANTITY), lineItem.getQuantity());
if (pageBuilder.getPositionCount() >= positionsPerPage) {
pages.add(pageBuilder.build());
pageBuilder.reset();
}
}
if (!pageBuilder.isEmpty()) {
pages.add(pageBuilder.build());
}
return pages;
}
Aggregations