Search in sources :

Example 1 with TestingTempStorageManager

use of com.facebook.presto.testing.TestingTempStorageManager in project presto by prestodb.

the class TestTempStorageSingleStreamSpiller method assertSpill.

private void assertSpill(boolean compression, boolean encryption) throws Exception {
    File spillPath = new File(tempDirectory, UUID.randomUUID().toString());
    TempStorageSingleStreamSpillerFactory spillerFactory = new TempStorageSingleStreamSpillerFactory(new TestingTempStorageManager(spillPath.toString()), // executor won't be closed, because we don't call destroy() on the spiller factory
    executor, new BlockEncodingManager(), new SpillerStats(), compression, encryption, LocalTempStorage.NAME);
    LocalMemoryContext memoryContext = newSimpleAggregatedMemoryContext().newLocalMemoryContext("test");
    SingleStreamSpiller singleStreamSpiller = spillerFactory.create(TYPES, new TestingSpillContext(), memoryContext);
    assertTrue(singleStreamSpiller instanceof TempStorageSingleStreamSpiller);
    TempStorageSingleStreamSpiller spiller = (TempStorageSingleStreamSpiller) singleStreamSpiller;
    Page page = buildPage();
    // The spillers will reserve memory in their constructors
    int retainedSizeForEmptyDataSink = toIntExact(new OutputStreamDataSink(new DynamicSliceOutput(0)).getRetainedSizeInBytes());
    assertEquals(memoryContext.getBytes(), retainedSizeForEmptyDataSink);
    spiller.spill(page).get();
    spiller.spill(Iterators.forArray(page, page, page)).get();
    assertEquals(listFiles(spillPath.toPath()).size(), 1);
    // The spillers release their memory reservations when they are closed, therefore at this point
    // they will have non-zero memory reservation.
    // assertEquals(memoryContext.getBytes(), 0);
    Iterator<Page> spilledPagesIterator = spiller.getSpilledPages();
    assertEquals(memoryContext.getBytes(), retainedSizeForEmptyDataSink);
    ImmutableList<Page> spilledPages = ImmutableList.copyOf(spilledPagesIterator);
    // The spillers release their memory reservations when they are closed, therefore at this point
    // they will have non-zero memory reservation.
    // assertEquals(memoryContext.getBytes(), 0);
    assertEquals(4, spilledPages.size());
    for (int i = 0; i < 4; ++i) {
        PageAssertions.assertPageEquals(TYPES, page, spilledPages.get(i));
    }
    // Assert the spill codec flags match the expected configuration
    try (InputStream is = newInputStream(listFiles(spillPath.toPath()).get(0))) {
        Iterator<SerializedPage> serializedPages = PagesSerdeUtil.readSerializedPages(new InputStreamSliceInput(is));
        assertTrue(serializedPages.hasNext(), "at least one page should be successfully read back");
        byte markers = serializedPages.next().getPageCodecMarkers();
        assertEquals(PageCodecMarker.COMPRESSED.isSet(markers), compression);
        assertEquals(PageCodecMarker.ENCRYPTED.isSet(markers), encryption);
    }
    spiller.close();
    assertEquals(listFiles(spillPath.toPath()).size(), 0);
    assertEquals(memoryContext.getBytes(), 0);
}
Also used : LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) Files.newInputStream(java.nio.file.Files.newInputStream) InputStream(java.io.InputStream) Page(com.facebook.presto.common.Page) SerializedPage(com.facebook.presto.spi.page.SerializedPage) BlockEncodingManager(com.facebook.presto.common.block.BlockEncodingManager) TestingTempStorageManager(com.facebook.presto.testing.TestingTempStorageManager) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) SerializedPage(com.facebook.presto.spi.page.SerializedPage) InputStreamSliceInput(io.airlift.slice.InputStreamSliceInput) File(java.io.File) OutputStreamDataSink(com.facebook.presto.common.io.OutputStreamDataSink)

Example 2 with TestingTempStorageManager

use of com.facebook.presto.testing.TestingTempStorageManager in project presto by prestodb.

the class TestAggregationOperator method testDistinctMaskWithNull.

@Test
public void testDistinctMaskWithNull() {
    AccumulatorFactory distinctFactory = COUNT.bind(ImmutableList.of(0), Optional.of(1), ImmutableList.of(BIGINT, BOOLEAN), ImmutableList.of(), ImmutableList.of(), null, // distinct
    true, new JoinCompiler(MetadataManager.createTestMetadataManager(), new FeaturesConfig()), ImmutableList.of(), false, TEST_SESSION, new TempStorageStandaloneSpillerFactory(new TestingTempStorageManager(), new BlockEncodingManager(), new NodeSpillConfig(), new FeaturesConfig(), new SpillerStats()));
    OperatorFactory operatorFactory = new AggregationOperatorFactory(0, new PlanNodeId("test"), Step.SINGLE, ImmutableList.of(distinctFactory), false);
    DriverContext driverContext = createTaskContext(executor, scheduledExecutor, TEST_SESSION).addPipelineContext(0, true, true, false).addDriverContext();
    ByteArrayBlock trueMaskAllNull = new ByteArrayBlock(4, Optional.of(new boolean[] { true, true, true, true }), /* all positions are null */
    new byte[] { 1, 1, 1, 1 });
    /* non-zero value is true, all masks are true */
    Block trueNullRleMask = new RunLengthEncodedBlock(trueMaskAllNull.getSingleValueBlock(0), 4);
    List<Page> input = ImmutableList.of(new Page(4, createLongsBlock(1, 2, 3, 4), trueMaskAllNull), new Page(4, createLongsBlock(5, 6, 7, 8), trueNullRleMask));
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT).row(// all rows should be filtered by nulls
    0L).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : JoinCompiler(com.facebook.presto.sql.gen.JoinCompiler) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) AggregationOperatorFactory(com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory) TempStorageStandaloneSpillerFactory(com.facebook.presto.spiller.TempStorageStandaloneSpillerFactory) NodeSpillConfig(com.facebook.presto.spiller.NodeSpillConfig) Page(com.facebook.presto.common.Page) SpillerStats(com.facebook.presto.spiller.SpillerStats) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) BlockEncodingManager(com.facebook.presto.common.block.BlockEncodingManager) TestingTempStorageManager(com.facebook.presto.testing.TestingTempStorageManager) AggregationOperatorFactory(com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory) AccumulatorFactory(com.facebook.presto.operator.aggregation.AccumulatorFactory) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) ByteArrayBlock(com.facebook.presto.common.block.ByteArrayBlock) BlockAssertions.createLongsBlock(com.facebook.presto.block.BlockAssertions.createLongsBlock) Block(com.facebook.presto.common.block.Block) ByteArrayBlock(com.facebook.presto.common.block.ByteArrayBlock) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Aggregations

Page (com.facebook.presto.common.Page)2 BlockEncodingManager (com.facebook.presto.common.block.BlockEncodingManager)2 TestingTempStorageManager (com.facebook.presto.testing.TestingTempStorageManager)2 BlockAssertions.createLongsBlock (com.facebook.presto.block.BlockAssertions.createLongsBlock)1 Block (com.facebook.presto.common.block.Block)1 ByteArrayBlock (com.facebook.presto.common.block.ByteArrayBlock)1 RunLengthEncodedBlock (com.facebook.presto.common.block.RunLengthEncodedBlock)1 OutputStreamDataSink (com.facebook.presto.common.io.OutputStreamDataSink)1 LocalMemoryContext (com.facebook.presto.memory.context.LocalMemoryContext)1 AggregationOperatorFactory (com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory)1 AccumulatorFactory (com.facebook.presto.operator.aggregation.AccumulatorFactory)1 SerializedPage (com.facebook.presto.spi.page.SerializedPage)1 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)1 NodeSpillConfig (com.facebook.presto.spiller.NodeSpillConfig)1 SpillerStats (com.facebook.presto.spiller.SpillerStats)1 TempStorageStandaloneSpillerFactory (com.facebook.presto.spiller.TempStorageStandaloneSpillerFactory)1 FeaturesConfig (com.facebook.presto.sql.analyzer.FeaturesConfig)1 JoinCompiler (com.facebook.presto.sql.gen.JoinCompiler)1 MaterializedResult (com.facebook.presto.testing.MaterializedResult)1 DynamicSliceOutput (io.airlift.slice.DynamicSliceOutput)1