use of com.facebook.presto.orc.OrcCorruptionException in project presto by prestodb.
the class LongDictionaryStreamReader method readBlock.
@Override
public Block readBlock(Type type) throws IOException {
if (!rowGroupOpen) {
openRowGroup();
}
if (readOffset > 0) {
if (presentStream != null) {
// skip ahead the present bit reader, but count the set bits
// and use this as the skip size for the length reader
readOffset = presentStream.countBitsSet(readOffset);
}
if (inDictionaryStream != null) {
inDictionaryStream.skip(readOffset);
}
if (readOffset > 0) {
if (dataStream == null) {
throw new OrcCorruptionException("Value is not null but data stream is not present");
}
dataStream.skip(readOffset);
}
}
if (nullVector.length < nextBatchSize) {
nullVector = new boolean[nextBatchSize];
}
if (dataVector.length < nextBatchSize) {
dataVector = new long[nextBatchSize];
}
if (presentStream == null) {
if (dataStream == null) {
throw new OrcCorruptionException("Value is not null but data stream is not present");
}
Arrays.fill(nullVector, false);
dataStream.nextLongVector(nextBatchSize, dataVector);
} else {
int nullValues = presentStream.getUnsetBits(nextBatchSize, nullVector);
if (nullValues != nextBatchSize) {
if (dataStream == null) {
throw new OrcCorruptionException("Value is not null but data stream is not present");
}
dataStream.nextLongVector(nextBatchSize, dataVector, nullVector);
}
}
if (inDictionary.length < nextBatchSize) {
inDictionary = new boolean[nextBatchSize];
}
if (inDictionaryStream == null) {
Arrays.fill(inDictionary, true);
} else {
inDictionaryStream.getSetBits(nextBatchSize, inDictionary, nullVector);
}
BlockBuilder builder = type.createBlockBuilder(new BlockBuilderStatus(), nextBatchSize);
for (int i = 0; i < nextBatchSize; i++) {
if (nullVector[i]) {
builder.appendNull();
} else if (inDictionary[i]) {
type.writeLong(builder, dictionary[((int) dataVector[i])]);
} else {
type.writeLong(builder, dataVector[i]);
}
}
readOffset = 0;
nextBatchSize = 0;
return builder.build();
}
use of com.facebook.presto.orc.OrcCorruptionException in project presto by prestodb.
the class LongDictionaryStreamReader method openRowGroup.
private void openRowGroup() throws IOException {
// read the dictionary
if (!dictionaryOpen && dictionarySize > 0) {
if (dictionary.length < dictionarySize) {
dictionary = new long[dictionarySize];
}
LongStream dictionaryStream = dictionaryDataStreamSource.openStream();
if (dictionaryStream == null) {
throw new OrcCorruptionException("Dictionary is not empty but data stream is not present");
}
dictionaryStream.nextLongVector(dictionarySize, dictionary);
}
dictionaryOpen = true;
presentStream = presentStreamSource.openStream();
inDictionaryStream = inDictionaryStreamSource.openStream();
dataStream = dataStreamSource.openStream();
rowGroupOpen = true;
}
use of com.facebook.presto.orc.OrcCorruptionException in project presto by prestodb.
the class LongDirectStreamReader method readBlock.
@Override
public Block readBlock(Type type) throws IOException {
if (!rowGroupOpen) {
openRowGroup();
}
if (readOffset > 0) {
if (presentStream != null) {
// skip ahead the present bit reader, but count the set bits
// and use this as the skip size for the data reader
readOffset = presentStream.countBitsSet(readOffset);
}
if (readOffset > 0) {
if (dataStream == null) {
throw new OrcCorruptionException("Value is not null but data stream is not present");
}
dataStream.skip(readOffset);
}
}
BlockBuilder builder = type.createBlockBuilder(new BlockBuilderStatus(), nextBatchSize);
if (presentStream == null) {
if (dataStream == null) {
throw new OrcCorruptionException("Value is not null but data stream is not present");
}
dataStream.nextLongVector(type, nextBatchSize, builder);
} else {
if (nullVector.length < nextBatchSize) {
nullVector = new boolean[nextBatchSize];
}
int nullValues = presentStream.getUnsetBits(nextBatchSize, nullVector);
if (nullValues != nextBatchSize) {
if (dataStream == null) {
throw new OrcCorruptionException("Value is not null but data stream is not present");
}
dataStream.nextLongVector(type, nextBatchSize, builder, nullVector);
} else {
for (int i = 0; i < nextBatchSize; i++) {
builder.appendNull();
}
}
}
readOffset = 0;
nextBatchSize = 0;
return builder.build();
}
use of com.facebook.presto.orc.OrcCorruptionException in project presto by prestodb.
the class TimestampStreamReader method readBlock.
@Override
public Block readBlock(Type type) throws IOException {
if (!rowGroupOpen) {
openRowGroup();
}
if (readOffset > 0) {
if (presentStream != null) {
// skip ahead the present bit reader, but count the set bits
// and use this as the skip size for the data reader
readOffset = presentStream.countBitsSet(readOffset);
}
if (readOffset > 0) {
if (secondsStream == null) {
throw new OrcCorruptionException("Value is not null but seconds stream is not present");
}
if (nanosStream == null) {
throw new OrcCorruptionException("Value is not null but nanos stream is not present");
}
secondsStream.skip(readOffset);
nanosStream.skip(readOffset);
}
}
if (secondsVector.length < nextBatchSize) {
secondsVector = new long[nextBatchSize];
}
if (nanosVector.length < nextBatchSize) {
nanosVector = new long[nextBatchSize];
}
BlockBuilder builder = type.createBlockBuilder(new BlockBuilderStatus(), nextBatchSize);
if (presentStream == null) {
if (secondsStream == null) {
throw new OrcCorruptionException("Value is not null but seconds stream is not present");
}
if (nanosStream == null) {
throw new OrcCorruptionException("Value is not null but nanos stream is not present");
}
secondsStream.nextLongVector(nextBatchSize, secondsVector);
nanosStream.nextLongVector(nextBatchSize, nanosVector);
// merge seconds and nanos together
for (int i = 0; i < nextBatchSize; i++) {
type.writeLong(builder, decodeTimestamp(secondsVector[i], nanosVector[i], baseTimestampInSeconds));
}
} else {
if (nullVector.length < nextBatchSize) {
nullVector = new boolean[nextBatchSize];
}
int nullValues = presentStream.getUnsetBits(nextBatchSize, nullVector);
if (nullValues != nextBatchSize) {
if (secondsStream == null) {
throw new OrcCorruptionException("Value is not null but seconds stream is not present");
}
if (nanosStream == null) {
throw new OrcCorruptionException("Value is not null but nanos stream is not present");
}
secondsStream.nextLongVector(nextBatchSize, secondsVector, nullVector);
nanosStream.nextLongVector(nextBatchSize, nanosVector, nullVector);
// merge seconds and nanos together
for (int i = 0; i < nextBatchSize; i++) {
if (nullVector[i]) {
builder.appendNull();
} else {
type.writeLong(builder, decodeTimestamp(secondsVector[i], nanosVector[i], baseTimestampInSeconds));
}
}
} else {
for (int i = 0; i < nextBatchSize; i++) {
builder.appendNull();
}
}
}
readOffset = 0;
nextBatchSize = 0;
return builder.build();
}
use of com.facebook.presto.orc.OrcCorruptionException in project presto by prestodb.
the class LongDictionaryBatchStreamReader method readBlock.
@Override
public Block readBlock() throws IOException {
if (!rowGroupOpen) {
openRowGroup();
}
if (readOffset > 0) {
if (presentStream != null) {
// skip ahead the present bit reader, but count the set bits
// and use this as the skip size for the length reader
readOffset = presentStream.countBitsSet(readOffset);
}
if (inDictionaryStream != null) {
inDictionaryStream.skip(readOffset);
}
if (readOffset > 0) {
if (dataStream == null) {
throw new OrcCorruptionException(streamDescriptor.getOrcDataSourceId(), "Value is not null but data stream is not present");
}
dataStream.skip(readOffset);
}
}
BlockBuilder builder = type.createBlockBuilder(null, nextBatchSize);
if (presentStream == null) {
// Data doesn't have nulls
if (dataStream == null) {
throw new OrcCorruptionException(streamDescriptor.getOrcDataSourceId(), "Value is not null but data stream is not present");
}
if (inDictionaryStream == null) {
for (int i = 0; i < nextBatchSize; i++) {
type.writeLong(builder, dictionary[((int) dataStream.next())]);
}
} else {
for (int i = 0; i < nextBatchSize; i++) {
long id = dataStream.next();
if (inDictionaryStream.nextBit()) {
type.writeLong(builder, dictionary[(int) id]);
} else {
type.writeLong(builder, id);
}
}
}
} else {
// Data has nulls
if (dataStream == null) {
// The only valid case for dataStream is null when data has nulls is that all values are nulls.
int nullValues = presentStream.getUnsetBits(nextBatchSize);
if (nullValues != nextBatchSize) {
throw new OrcCorruptionException(streamDescriptor.getOrcDataSourceId(), "Value is not null but data stream is not present");
}
for (int i = 0; i < nextBatchSize; i++) {
builder.appendNull();
}
} else {
for (int i = 0; i < nextBatchSize; i++) {
if (!presentStream.nextBit()) {
builder.appendNull();
} else {
long id = dataStream.next();
if (inDictionaryStream == null || inDictionaryStream.nextBit()) {
type.writeLong(builder, dictionary[(int) id]);
} else {
type.writeLong(builder, id);
}
}
}
}
}
readOffset = 0;
nextBatchSize = 0;
return builder.build();
}
Aggregations