use of com.facebook.presto.orc.reader.SliceSelectiveStreamReader in project presto by prestodb.
the class TestOrcSelectiveStreamReaders method testEmptyStrings.
/**
* This test tests SliceDirectSelectiveStreamReader for the case where all elements to read are empty strings. The output Block should be a valid VariableWidthBlock with an
* empty Slice. It is to simulate a problem seen in production. The state of SliceDirectSelectiveStreamReader to reproduce the problem is:
* - dataStream: null
* - presentStream: null
* - lengthStream: not null
* - filter: null
* - outputRequired: true
* - offsets array: non zeros
* The test issues two reads, the first one reads a non-empty string and populates non-zero offsets. The second one reads the empty string with the above conditions met.
*/
@Test
public void testEmptyStrings() throws Exception {
Type type = VARCHAR;
List<Type> types = ImmutableList.of(type);
List<List<?>> values = ImmutableList.of(ImmutableList.of("a", ""));
for (OrcTester.Format format : formats) {
if (!types.stream().allMatch(readType -> format.supportsType(readType))) {
return;
}
for (CompressionKind compression : compressions) {
TempFile tempFile = new TempFile();
writeOrcColumnsPresto(tempFile.getFile(), format, compression, Optional.empty(), types, values, new OrcWriterStats());
OrcPredicate orcPredicate = createOrcPredicate(types, values, DWRF, false);
Map<Integer, Type> includedColumns = IntStream.range(0, types.size()).boxed().collect(toImmutableMap(Function.identity(), types::get));
List<Integer> outputColumns = IntStream.range(0, types.size()).boxed().collect(toImmutableList());
OrcAggregatedMemoryContext systemMemoryUsage = new TestingHiveOrcAggregatedMemoryContext();
try (OrcSelectiveRecordReader recordReader = createCustomOrcSelectiveRecordReader(tempFile.getFile(), format.getOrcEncoding(), orcPredicate, types, 1, ImmutableMap.of(), ImmutableList.of(), ImmutableMap.of(), OrcTester.OrcReaderSettings.builder().build().getRequiredSubfields(), ImmutableMap.of(), ImmutableMap.of(), includedColumns, outputColumns, false, systemMemoryUsage, false)) {
assertEquals(recordReader.getReaderPosition(), 0);
assertEquals(recordReader.getFilePosition(), 0);
SelectiveStreamReader streamReader = recordReader.getStreamReaders()[0];
// Read the first non-empty element. Do not call streamReader.getBlock() to preserve the offsets array in SliceDirectSelectiveStreamReader.
int batchSize = min(recordReader.prepareNextBatch(), 1);
int[] positions = IntStream.range(0, batchSize).toArray();
streamReader.read(0, positions, batchSize);
recordReader.batchRead(batchSize);
// Read the second element: an empty string. Set the dataStream in SliceDirectSelectiveStreamReader to null to simulate the conditions causing the problem.
((SliceSelectiveStreamReader) streamReader).resetDataStream();
batchSize = min(recordReader.prepareNextBatch(), 1);
positions = IntStream.range(0, batchSize).toArray();
streamReader.read(0, positions, batchSize);
recordReader.batchRead(batchSize);
Block block = streamReader.getBlock(positions, batchSize);
List<?> expectedValues = ImmutableList.of("");
assertBlockEquals(type, block, expectedValues, 0);
assertEquals(recordReader.getReaderPosition(), 1);
assertEquals(recordReader.getFilePosition(), 1);
}
}
}
}
Aggregations