use of com.facebook.presto.orc.OrcCorruptionException in project presto by prestodb.
the class DecimalBatchStreamReader method readBlock.
@Override
public Block readBlock() throws IOException {
if (!rowGroupOpen) {
openRowGroup();
}
seekToOffset();
if (decimalStream == null && scaleStream == null && presentStream != null) {
presentStream.skip(nextBatchSize);
Block nullValueBlock = RunLengthEncodedBlock.create(type, null, nextBatchSize);
readOffset = 0;
nextBatchSize = 0;
return nullValueBlock;
}
BlockBuilder builder = type.createBlockBuilder(null, nextBatchSize);
if (presentStream == null) {
if (decimalStream == null) {
throw new OrcCorruptionException(streamDescriptor.getOrcDataSourceId(), "Value is not null but decimal stream is not present");
}
if (scaleStream == null) {
throw new OrcCorruptionException(streamDescriptor.getOrcDataSourceId(), "Value is not null but scale stream is not present");
}
for (int i = 0; i < nextBatchSize; i++) {
long sourceScale = scaleStream.next();
if (type.isShort()) {
long rescaledDecimal = Decimals.rescale(decimalStream.nextLong(), (int) sourceScale, type.getScale());
type.writeLong(builder, rescaledDecimal);
} else {
Slice decimal = UnscaledDecimal128Arithmetic.unscaledDecimal();
Slice rescaledDecimal = UnscaledDecimal128Arithmetic.unscaledDecimal();
decimalStream.nextLongDecimal(decimal);
rescale(decimal, (int) (type.getScale() - sourceScale), rescaledDecimal);
type.writeSlice(builder, rescaledDecimal);
}
}
} else {
verify(decimalStream != null);
verify(scaleStream != null);
for (int i = 0; i < nextBatchSize; i++) {
if (presentStream.nextBit()) {
// The current row is not null
long sourceScale = scaleStream.next();
if (type.isShort()) {
long rescaledDecimal = Decimals.rescale(decimalStream.nextLong(), (int) sourceScale, type.getScale());
type.writeLong(builder, rescaledDecimal);
} else {
Slice decimal = UnscaledDecimal128Arithmetic.unscaledDecimal();
Slice rescaledDecimal = UnscaledDecimal128Arithmetic.unscaledDecimal();
decimalStream.nextLongDecimal(decimal);
rescale(decimal, (int) (type.getScale() - sourceScale), rescaledDecimal);
type.writeSlice(builder, rescaledDecimal);
}
} else {
builder.appendNull();
}
}
}
readOffset = 0;
nextBatchSize = 0;
return builder.build();
}
use of com.facebook.presto.orc.OrcCorruptionException in project presto by prestodb.
the class DoubleBatchStreamReader 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 data reader
readOffset = presentStream.countBitsSet(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);
}
}
if (dataStream == null && presentStream != null) {
presentStream.skip(nextBatchSize);
Block nullValueBlock = RunLengthEncodedBlock.create(DOUBLE, null, nextBatchSize);
readOffset = 0;
nextBatchSize = 0;
return nullValueBlock;
}
BlockBuilder builder = DOUBLE.createBlockBuilder(null, nextBatchSize);
if (presentStream == null) {
if (dataStream == null) {
throw new OrcCorruptionException(streamDescriptor.getOrcDataSourceId(), "Value is not null but data stream is not present");
}
dataStream.nextVector(DOUBLE, nextBatchSize, builder);
} else {
for (int i = 0; i < nextBatchSize; i++) {
if (presentStream.nextBit()) {
DOUBLE.writeDouble(builder, dataStream.next());
} else {
builder.appendNull();
}
}
}
readOffset = 0;
nextBatchSize = 0;
return builder.build();
}
use of com.facebook.presto.orc.OrcCorruptionException in project presto by prestodb.
the class LongInputStreamV2 method readValues.
// This comes from the Apache Hive ORC code
private void readValues() throws IOException {
lastReadInputCheckpoint = input.getCheckpoint();
// read the first 2 bits and determine the encoding type
int firstByte = input.read();
if (firstByte < 0) {
throw new OrcCorruptionException(input.getOrcDataSourceId(), "Read past end of RLE integer");
}
int enc = (firstByte >>> 6) & 0x03;
if (EncodingType.SHORT_REPEAT.ordinal() == enc) {
readShortRepeatValues(firstByte);
} else if (EncodingType.DIRECT.ordinal() == enc) {
readDirectValues(firstByte);
} else if (EncodingType.PATCHED_BASE.ordinal() == enc) {
readPatchedBaseValues(firstByte);
} else {
readDeltaValues(firstByte);
}
}
Aggregations