Search in sources :

Example 56 with Page

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));
}
Also used : GroupByHash.createGroupByHash(com.facebook.presto.operator.GroupByHash.createGroupByHash) BlockAssertions.createLongsBlock(com.facebook.presto.block.BlockAssertions.createLongsBlock) BlockAssertions.createLongSequenceBlock(com.facebook.presto.block.BlockAssertions.createLongSequenceBlock) BlockAssertions.createStringSequenceBlock(com.facebook.presto.block.BlockAssertions.createStringSequenceBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) TypeUtils.getHashBlock(com.facebook.presto.type.TypeUtils.getHashBlock) Block(com.facebook.presto.common.block.Block) Page(com.facebook.presto.common.Page) Test(org.testng.annotations.Test)

Example 57 with Page

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GroupByHash.createGroupByHash(com.facebook.presto.operator.GroupByHash.createGroupByHash) BlockAssertions.createLongsBlock(com.facebook.presto.block.BlockAssertions.createLongsBlock) BlockAssertions.createLongSequenceBlock(com.facebook.presto.block.BlockAssertions.createLongSequenceBlock) BlockAssertions.createStringSequenceBlock(com.facebook.presto.block.BlockAssertions.createStringSequenceBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) TypeUtils.getHashBlock(com.facebook.presto.type.TypeUtils.getHashBlock) Block(com.facebook.presto.common.block.Block) Page(com.facebook.presto.common.Page) Test(org.testng.annotations.Test)

Example 58 with Page

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());
}
Also used : Page(com.facebook.presto.common.Page)

Example 59 with Page

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());
    }
}
Also used : Page(com.facebook.presto.common.Page) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 60 with Page

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;
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) LineItem(io.airlift.tpch.LineItem) Page(com.facebook.presto.common.Page) PageBuilder(com.facebook.presto.common.PageBuilder) LineItemGenerator(io.airlift.tpch.LineItemGenerator)

Aggregations

Page (com.facebook.presto.common.Page)545 Test (org.testng.annotations.Test)273 Block (com.facebook.presto.common.block.Block)146 Type (com.facebook.presto.common.type.Type)129 MaterializedResult (com.facebook.presto.testing.MaterializedResult)102 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)89 ImmutableList (com.google.common.collect.ImmutableList)73 DataSize (io.airlift.units.DataSize)69 RowPagesBuilder (com.facebook.presto.RowPagesBuilder)65 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)52 ArrayList (java.util.ArrayList)50 List (java.util.List)48 Optional (java.util.Optional)44 RunLengthEncodedBlock (com.facebook.presto.common.block.RunLengthEncodedBlock)43 OperatorAssertion.toMaterializedResult (com.facebook.presto.operator.OperatorAssertion.toMaterializedResult)38 PrestoException (com.facebook.presto.spi.PrestoException)38 TestingTaskContext (com.facebook.presto.testing.TestingTaskContext)36 ArrayType (com.facebook.presto.common.type.ArrayType)35 IOException (java.io.IOException)31 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)29