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);
}
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;
}
}
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);
}
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);
}
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();
}
Aggregations