Search in sources :

Example 51 with Page

use of com.facebook.presto.common.Page in project presto by prestodb.

the class TestAggregationOperator method testMemoryTracking.

private void testMemoryTracking(boolean useSystemMemory) throws Exception {
    Page input = getOnlyElement(rowPagesBuilder(BIGINT).addSequencePage(100, 0).build());
    OperatorFactory operatorFactory = new AggregationOperatorFactory(0, new PlanNodeId("test"), Step.SINGLE, ImmutableList.of(LONG_SUM.bind(ImmutableList.of(0), Optional.empty())), useSystemMemory);
    DriverContext driverContext = createTaskContext(executor, scheduledExecutor, TEST_SESSION).addPipelineContext(0, true, true, false).addDriverContext();
    try (Operator operator = operatorFactory.createOperator(driverContext)) {
        assertTrue(operator.needsInput());
        operator.addInput(input);
        if (useSystemMemory) {
            assertThat(driverContext.getSystemMemoryUsage()).isGreaterThan(0);
            assertEquals(driverContext.getMemoryUsage(), 0);
        } else {
            assertEquals(driverContext.getSystemMemoryUsage(), 0);
            assertThat(driverContext.getMemoryUsage()).isGreaterThan(0);
        }
        toPages(operator, emptyIterator());
    }
    assertEquals(driverContext.getSystemMemoryUsage(), 0);
    assertEquals(driverContext.getMemoryUsage(), 0);
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) AggregationOperatorFactory(com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory) AggregationOperatorFactory(com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory) Page(com.facebook.presto.common.Page)

Example 52 with Page

use of com.facebook.presto.common.Page in project presto by prestodb.

the class TestFileFragmentResultCacheManager method testBasic.

@Test(timeOut = 30_000)
public void testBasic() throws Exception {
    URI cacheDirectory = getNewCacheDirectory("testBasic");
    FragmentCacheStats stats = new FragmentCacheStats();
    FileFragmentResultCacheManager cacheManager = fileFragmentResultCacheManager(stats, cacheDirectory);
    // Test fetching new fragment. Current cache status: empty
    assertFalse(cacheManager.get(SERIALIZED_PLAN_FRAGMENT_1, SPLIT_1).isPresent());
    assertEquals(stats.getCacheMiss(), 1);
    assertEquals(stats.getCacheHit(), 0);
    assertEquals(stats.getCacheEntries(), 0);
    assertEquals(stats.getCacheSizeInBytes(), 0);
    // Test empty page. Current cache status: empty
    cacheManager.put(SERIALIZED_PLAN_FRAGMENT_1, SPLIT_1, ImmutableList.of()).get();
    Optional<Iterator<Page>> result = cacheManager.get(SERIALIZED_PLAN_FRAGMENT_1, SPLIT_1);
    assertTrue(result.isPresent());
    assertFalse(result.get().hasNext());
    assertEquals(stats.getCacheMiss(), 1);
    assertEquals(stats.getCacheHit(), 1);
    assertEquals(stats.getCacheEntries(), 1);
    assertEquals(stats.getCacheSizeInBytes(), 0);
    // Test non-empty page. Current cache status: { (plan1, split1) -> [] }
    List<Page> pages = ImmutableList.of(new Page(createStringsBlock("plan-1-split-2")));
    cacheManager.put(SERIALIZED_PLAN_FRAGMENT_2, SPLIT_2, pages).get();
    result = cacheManager.get(SERIALIZED_PLAN_FRAGMENT_2, SPLIT_2);
    assertTrue(result.isPresent());
    assertPagesEqual(result.get(), pages.iterator());
    assertEquals(stats.getCacheMiss(), 1);
    assertEquals(stats.getCacheHit(), 2);
    assertEquals(stats.getCacheEntries(), 2);
    assertEquals(stats.getCacheSizeInBytes(), getCachePhysicalSize(cacheDirectory));
    // Test cache miss for plan mismatch and split mismatch. Current cache status: { (plan1, split1) -> [], (plan2, split2) -> ["plan-1-split-2"] }
    cacheManager.get(SERIALIZED_PLAN_FRAGMENT_1, SPLIT_2);
    assertEquals(stats.getCacheMiss(), 2);
    assertEquals(stats.getCacheHit(), 2);
    assertEquals(stats.getCacheEntries(), 2);
    cacheManager.get(SERIALIZED_PLAN_FRAGMENT_2, SPLIT_1);
    assertEquals(stats.getCacheMiss(), 3);
    assertEquals(stats.getCacheHit(), 2);
    assertEquals(stats.getCacheEntries(), 2);
    assertEquals(stats.getCacheSizeInBytes(), getCachePhysicalSize(cacheDirectory));
    // Test cache invalidation
    cacheManager.invalidateAllCache();
    assertEquals(stats.getCacheMiss(), 3);
    assertEquals(stats.getCacheHit(), 2);
    assertEquals(stats.getCacheEntries(), 0);
    assertEquals(stats.getCacheRemoval(), 2);
    assertEquals(stats.getCacheSizeInBytes(), 0);
    cleanupCacheDirectory(cacheDirectory);
}
Also used : Iterator(java.util.Iterator) Page(com.facebook.presto.common.Page) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 53 with Page

use of com.facebook.presto.common.Page in project presto by prestodb.

the class TestGroupByHash method testForceRehash.

@Test
public void testForceRehash() {
    // Create a page with positionCount >> expected size of groupByHash
    Block valuesBlock = BlockAssertions.createStringSequenceBlock(0, 100);
    Block hashBlock = TypeUtils.getHashBlock(ImmutableList.of(VARCHAR), valuesBlock);
    // Create group by hash with extremely small size
    GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(VARCHAR), new int[] { 0 }, Optional.of(1), 4, JOIN_COMPILER);
    groupByHash.getGroupIds(new Page(valuesBlock, hashBlock)).process();
    // Ensure that all groups are present in group by hash
    for (int i = 0; i < valuesBlock.getPositionCount(); i++) {
        assertTrue(groupByHash.contains(i, new Page(valuesBlock, hashBlock), CONTAINS_CHANNELS));
    }
}
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 54 with Page

use of com.facebook.presto.common.Page in project presto by prestodb.

the class TestGroupByHash method testAppendToMultipleTuplesPerGroup.

@Test
public void testAppendToMultipleTuplesPerGroup() {
    List<Long> values = new ArrayList<>();
    for (long i = 0; i < 100; i++) {
        values.add(i % 50);
    }
    Block valuesBlock = BlockAssertions.createLongsBlock(values);
    Block hashBlock = TypeUtils.getHashBlock(ImmutableList.of(BIGINT), valuesBlock);
    GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(BIGINT), new int[] { 0 }, Optional.of(1), 100, JOIN_COMPILER);
    groupByHash.getGroupIds(new Page(valuesBlock, hashBlock)).process();
    assertEquals(groupByHash.getGroupCount(), 50);
    PageBuilder pageBuilder = new PageBuilder(groupByHash.getTypes());
    for (int i = 0; i < groupByHash.getGroupCount(); i++) {
        pageBuilder.declarePosition();
        groupByHash.appendValuesTo(i, pageBuilder, 0);
    }
    Page outputPage = pageBuilder.build();
    assertEquals(outputPage.getPositionCount(), 50);
    BlockAssertions.assertBlockEquals(BIGINT, outputPage.getBlock(0), BlockAssertions.createLongSequenceBlock(0, 50));
}
Also used : ArrayList(java.util.ArrayList) 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) PageBuilder(com.facebook.presto.common.PageBuilder) Test(org.testng.annotations.Test)

Example 55 with Page

use of com.facebook.presto.common.Page in project presto by prestodb.

the class TestGroupByHash method testNullGroup.

@Test
public void testNullGroup() {
    GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(BIGINT), new int[] { 0 }, Optional.of(1), 100, JOIN_COMPILER);
    Block block = createLongsBlock((Long) null);
    Block hashBlock = getHashBlock(ImmutableList.of(BIGINT), block);
    Page page = new Page(block, hashBlock);
    groupByHash.addPage(page).process();
    // Add enough values to force a rehash
    block = createLongSequenceBlock(1, 132748);
    hashBlock = getHashBlock(ImmutableList.of(BIGINT), block);
    page = new Page(block, hashBlock);
    groupByHash.addPage(page).process();
    block = createLongsBlock(0);
    hashBlock = getHashBlock(ImmutableList.of(BIGINT), block);
    page = new Page(block, hashBlock);
    assertFalse(groupByHash.contains(0, page, CONTAINS_CHANNELS));
}
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)

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