Search in sources :

Example 16 with BlockEncodingManager

use of com.facebook.presto.common.block.BlockEncodingManager in project presto by prestodb.

the class TestFileSingleStreamSpiller method assertSpill.

private void assertSpill(boolean compression, boolean encryption) throws Exception {
    File spillPath = new File(tempDirectory, UUID.randomUUID().toString());
    FileSingleStreamSpillerFactory spillerFactory = new FileSingleStreamSpillerFactory(// executor won't be closed, because we don't call destroy() on the spiller factory
    executor, new BlockEncodingManager(), new SpillerStats(), ImmutableList.of(spillPath.toPath()), 1.0, compression, encryption);
    LocalMemoryContext memoryContext = newSimpleAggregatedMemoryContext().newLocalMemoryContext("test");
    SingleStreamSpiller singleStreamSpiller = spillerFactory.create(TYPES, new TestingSpillContext(), memoryContext);
    assertTrue(singleStreamSpiller instanceof FileSingleStreamSpiller);
    FileSingleStreamSpiller spiller = (FileSingleStreamSpiller) singleStreamSpiller;
    Page page = buildPage();
    // The spillers will reserve memory in their constructors
    assertEquals(memoryContext.getBytes(), 4096);
    spiller.spill(page).get();
    spiller.spill(Iterators.forArray(page, page, page)).get();
    assertEquals(listFiles(spillPath.toPath()).size(), 1);
    // 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);
    }
    // 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(), FileSingleStreamSpiller.BUFFER_SIZE);
    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));
    }
    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) SerializedPage(com.facebook.presto.spi.page.SerializedPage) InputStreamSliceInput(io.airlift.slice.InputStreamSliceInput) File(java.io.File)

Example 17 with BlockEncodingManager

use of com.facebook.presto.common.block.BlockEncodingManager in project presto by prestodb.

the class TestingThriftUdfServerModule method configure.

@Override
public void configure(Binder binder) {
    binder.bind(EchoFirstInputThriftUdfService.class).in(Scopes.SINGLETON);
    binder.bind(BlockEncodingSerde.class).toInstance(new BlockEncodingManager());
    driftServerBinder(binder).bindService(EchoFirstInputThriftUdfService.class);
}
Also used : BlockEncodingManager(com.facebook.presto.common.block.BlockEncodingManager) BlockEncodingSerde(com.facebook.presto.common.block.BlockEncodingSerde)

Aggregations

BlockEncodingManager (com.facebook.presto.common.block.BlockEncodingManager)17 Test (org.testng.annotations.Test)7 Page (com.facebook.presto.common.Page)5 PagesSerdeFactory (com.facebook.presto.execution.buffer.PagesSerdeFactory)5 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)5 BlockEncodingSerde (com.facebook.presto.common.block.BlockEncodingSerde)4 Type (com.facebook.presto.common.type.Type)3 PartitionedOutputBuffer (com.facebook.presto.execution.buffer.PartitionedOutputBuffer)3 TaskExecutor (com.facebook.presto.execution.executor.TaskExecutor)3 FeaturesConfig (com.facebook.presto.sql.analyzer.FeaturesConfig)3 Path (java.nio.file.Path)3 OutputBuffers (com.facebook.presto.execution.buffer.OutputBuffers)2 LocalMemoryContext (com.facebook.presto.memory.context.LocalMemoryContext)2 SerializedPage (com.facebook.presto.spi.page.SerializedPage)2 DynamicSliceOutput (io.airlift.slice.DynamicSliceOutput)2 DataSize (io.airlift.units.DataSize)2 JsonCodec.jsonCodec (com.facebook.airlift.json.JsonCodec.jsonCodec)1 JsonObjectMapperProvider (com.facebook.airlift.json.JsonObjectMapperProvider)1 Session (com.facebook.presto.Session)1 TEST_SESSION (com.facebook.presto.SessionTestUtils.TEST_SESSION)1