Search in sources :

Example 6 with ColumnReader

use of io.prestosql.orc.reader.ColumnReader in project hetu-core by openlookeng.

the class TestCachingColumnReader method testBlockCachedOnStartRowGroup.

@Test
public void testBlockCachedOnStartRowGroup() throws Exception {
    ColumnReader columnReader = mock(ColumnReader.class);
    Cache<OrcRowDataCacheKey, Block> cache = spy(CacheBuilder.newBuilder().build());
    CachingColumnReader cachingColumnReader = new CachingColumnReader(columnReader, column, cache);
    InputStreamSources inputStreamSources = mock(InputStreamSources.class);
    StreamSourceMeta streamSourceMeta = new StreamSourceMeta();
    OrcDataSourceId orcDataSourceId = new OrcDataSourceId("2");
    streamSourceMeta.setDataSourceId(orcDataSourceId);
    Block block = mock(Block.class);
    when(inputStreamSources.getStreamSourceMeta()).thenReturn(streamSourceMeta);
    when(columnReader.readBlock()).thenReturn(block);
    cachingColumnReader.startRowGroup(inputStreamSources);
    verify(columnReader, atLeastOnce()).startRowGroup(eq(inputStreamSources));
    verify(columnReader, times(1)).readBlock();
    verify(cache, times(1)).get(any(OrcRowDataCacheKey.class), any(Callable.class));
    assertEquals(cache.size(), 1);
}
Also used : InputStreamSources(io.prestosql.orc.stream.InputStreamSources) Block(io.prestosql.spi.block.Block) CachingColumnReader(io.prestosql.orc.reader.CachingColumnReader) ColumnReader(io.prestosql.orc.reader.ColumnReader) StreamSourceMeta(io.prestosql.orc.stream.StreamSourceMeta) CachingColumnReader(io.prestosql.orc.reader.CachingColumnReader) Callable(java.util.concurrent.Callable) Test(org.testng.annotations.Test)

Example 7 with ColumnReader

use of io.prestosql.orc.reader.ColumnReader in project hetu-core by openlookeng.

the class TestCachingColumnReader method testDelegateThrowsException.

@Test(expectedExceptions = IOException.class)
public void testDelegateThrowsException() throws IOException {
    ColumnReader columnReader = mock(ColumnReader.class);
    Cache<OrcRowDataCacheKey, Block> cache = spy(CacheBuilder.newBuilder().build());
    CachingColumnReader cachingColumnReader = new CachingColumnReader(columnReader, column, cache);
    InputStreamSources inputStreamSources = mock(InputStreamSources.class);
    StreamSourceMeta streamSourceMeta = new StreamSourceMeta();
    OrcDataSourceId orcDataSourceId = new OrcDataSourceId("2");
    streamSourceMeta.setDataSourceId(orcDataSourceId);
    when(inputStreamSources.getStreamSourceMeta()).thenReturn(streamSourceMeta);
    when(columnReader.readBlock()).thenThrow(new OrcCorruptionException(orcDataSourceId, "Value is null but stream is missing")).thenThrow(new OrcCorruptionException(orcDataSourceId, "Value is null but stream is missing"));
    try {
        cachingColumnReader.startRowGroup(inputStreamSources);
    } catch (IOException ioEx) {
        verify(columnReader, atLeastOnce()).startRowGroup(eq(inputStreamSources));
        verify(columnReader, times(2)).readBlock();
        assertEquals(cache.size(), 0);
        throw ioEx;
    }
}
Also used : InputStreamSources(io.prestosql.orc.stream.InputStreamSources) Block(io.prestosql.spi.block.Block) CachingColumnReader(io.prestosql.orc.reader.CachingColumnReader) ColumnReader(io.prestosql.orc.reader.ColumnReader) StreamSourceMeta(io.prestosql.orc.stream.StreamSourceMeta) IOException(java.io.IOException) CachingColumnReader(io.prestosql.orc.reader.CachingColumnReader) Test(org.testng.annotations.Test)

Example 8 with ColumnReader

use of io.prestosql.orc.reader.ColumnReader in project hetu-core by openlookeng.

the class TestCachingColumnReader method testReadBlockRetrievesFromCache.

@Test
public void testReadBlockRetrievesFromCache() throws Exception {
    ColumnReader columnReader = mock(ColumnReader.class);
    Cache<OrcRowDataCacheKey, Block> cache = spy(CacheBuilder.newBuilder().build());
    CachingColumnReader cachingColumnReader = new CachingColumnReader(columnReader, column, cache);
    InputStreamSources inputStreamSources = mock(InputStreamSources.class);
    StreamSourceMeta streamSourceMeta = new StreamSourceMeta();
    OrcDataSourceId orcDataSourceId = new OrcDataSourceId("2");
    streamSourceMeta.setDataSourceId(orcDataSourceId);
    when(inputStreamSources.getStreamSourceMeta()).thenReturn(streamSourceMeta);
    Block block = mock(Block.class);
    when(columnReader.readBlock()).thenReturn(block);
    cachingColumnReader.startRowGroup(inputStreamSources);
    cachingColumnReader.prepareNextRead(10);
    cachingColumnReader.readBlock();
    cachingColumnReader.prepareNextRead(20);
    cachingColumnReader.readBlock();
    verify(columnReader, atLeastOnce()).startRowGroup(eq(inputStreamSources));
    verify(columnReader, times(1)).readBlock();
    InOrder inOrder = inOrder(block);
    inOrder.verify(block, times(1)).getRegion(0, 10);
    inOrder.verify(block, times(1)).getRegion(10, 20);
    verify(cache, times(1)).get(any(OrcRowDataCacheKey.class), any(Callable.class));
    assertEquals(cache.size(), 1);
}
Also used : InputStreamSources(io.prestosql.orc.stream.InputStreamSources) InOrder(org.mockito.InOrder) Block(io.prestosql.spi.block.Block) CachingColumnReader(io.prestosql.orc.reader.CachingColumnReader) ColumnReader(io.prestosql.orc.reader.ColumnReader) StreamSourceMeta(io.prestosql.orc.stream.StreamSourceMeta) CachingColumnReader(io.prestosql.orc.reader.CachingColumnReader) Callable(java.util.concurrent.Callable) Test(org.testng.annotations.Test)

Example 9 with ColumnReader

use of io.prestosql.orc.reader.ColumnReader in project hetu-core by openlookeng.

the class TestCachingColumnReader method testGetRetainedSizeInBytes.

@Test
public void testGetRetainedSizeInBytes() {
    ColumnReader streamReader = mock(ColumnReader.class);
    Cache<OrcRowDataCacheKey, Block> cache = spy(CacheBuilder.newBuilder().build());
    CachingColumnReader cachingColumnReader = new CachingColumnReader(streamReader, column, cache);
    when(streamReader.getRetainedSizeInBytes()).thenReturn((long) 1);
    assertEquals(cachingColumnReader.getRetainedSizeInBytes(), 1);
}
Also used : Block(io.prestosql.spi.block.Block) CachingColumnReader(io.prestosql.orc.reader.CachingColumnReader) ColumnReader(io.prestosql.orc.reader.ColumnReader) CachingColumnReader(io.prestosql.orc.reader.CachingColumnReader) Test(org.testng.annotations.Test)

Example 10 with ColumnReader

use of io.prestosql.orc.reader.ColumnReader in project hetu-core by openlookeng.

the class TestCachingColumnReader method testCachingStringReaderClosed.

@Test
public void testCachingStringReaderClosed() {
    ColumnReader streamReader = mock(ColumnReader.class);
    Cache<OrcRowDataCacheKey, Block> cache = spy(CacheBuilder.newBuilder().build());
    CachingColumnReader cachingColumnReader = new CachingColumnReader(streamReader, column, cache);
    cachingColumnReader.close();
    verify(streamReader, times(1)).close();
}
Also used : Block(io.prestosql.spi.block.Block) CachingColumnReader(io.prestosql.orc.reader.CachingColumnReader) ColumnReader(io.prestosql.orc.reader.ColumnReader) CachingColumnReader(io.prestosql.orc.reader.CachingColumnReader) Test(org.testng.annotations.Test)

Aggregations

ColumnReader (io.prestosql.orc.reader.ColumnReader)15 Block (io.prestosql.spi.block.Block)11 Test (org.testng.annotations.Test)11 CachingColumnReader (io.prestosql.orc.reader.CachingColumnReader)7 OrcColumnId (io.prestosql.orc.metadata.OrcColumnId)6 InputStreamSources (io.prestosql.orc.stream.InputStreamSources)5 IOException (java.io.IOException)5 ColumnMetadata (io.prestosql.orc.metadata.ColumnMetadata)4 OrcType (io.prestosql.orc.metadata.OrcType)4 DateColumnReader (io.prestosql.orc.reader.DateColumnReader)4 IntegerColumnReader (io.prestosql.orc.reader.IntegerColumnReader)4 LongColumnReader (io.prestosql.orc.reader.LongColumnReader)4 ShortColumnReader (io.prestosql.orc.reader.ShortColumnReader)4 StreamSourceMeta (io.prestosql.orc.stream.StreamSourceMeta)4 Page (io.prestosql.spi.Page)4 PeekingIterator (com.google.common.collect.PeekingIterator)3 Logger (io.airlift.log.Logger)3 Slice (io.airlift.slice.Slice)3 DataSize (io.airlift.units.DataSize)3 AggregatedMemoryContext (io.prestosql.memory.context.AggregatedMemoryContext)3