use of io.trino.orc.OrcCorruptionException in project trino by trinodb.
the class DecimalInputStream method decodeLongDecimalTail.
private int decodeLongDecimalTail(long[] result, int count, int batchSize) throws IOException {
boolean negative = false;
long low = 0;
long middle = 0;
int high = 0;
long value;
boolean last = false;
if (blockOffset == block.length()) {
advance();
}
int offset = 0;
while (true) {
value = block.getByte(blockOffset);
blockOffset++;
if (offset == 0) {
negative = (value & 1) == 1;
low |= (value & 0x7F);
} else if (offset < 8) {
low |= (value & 0x7F) << (offset * 7);
} else if (offset < 16) {
middle |= (value & 0x7F) << ((offset - 8) * 7);
} else if (offset < 19) {
high |= (value & 0x7F) << ((offset - 16) * 7);
} else {
throw new OrcCorruptionException(chunkLoader.getOrcDataSourceId(), "Decimal exceeds 128 bits");
}
offset++;
if ((value & 0x80) == 0) {
if (high > 0xFF_FF) {
// only 127 - (55 + 56) = 16 bits allowed in high
throw new OrcCorruptionException(chunkLoader.getOrcDataSourceId(), "Decimal exceeds 128 bits");
}
emitLongDecimal(result, count, low, middle, high, negative);
count++;
low = 0;
middle = 0;
high = 0;
offset = 0;
if (blockOffset == block.length()) {
// reset the block and loop around to optimized decoding
break;
}
if (last || count == batchSize) {
break;
}
} else if (blockOffset == block.length()) {
last = true;
advance();
}
}
return count;
}
use of io.trino.orc.OrcCorruptionException in project trino by trinodb.
the class DecimalInputStream method nextShortDecimal.
@SuppressWarnings("PointlessBitwiseExpression")
public void nextShortDecimal(long[] result, int batchSize) throws IOException {
verify(result.length >= batchSize);
int count = 0;
while (count < batchSize) {
if (blockOffset == block.length()) {
advance();
}
while (blockOffset <= block.length() - 12) {
// we'll read 1 longs + 1 int
long low;
int high = 0;
// low bits
long current = block.getLong(blockOffset);
int zeros = Long.numberOfTrailingZeros(~current & LONG_MASK);
int end = (zeros + 1) / 8;
blockOffset += end;
low = (current & 0x7F_00_00_00_00_00_00_00L) >>> 7;
low |= (current & 0x7F_00_00_00_00_00_00L) >>> 6;
low |= (current & 0x7F_00_00_00_00_00L) >>> 5;
low |= (current & 0x7F_00_00_00_00L) >>> 4;
low |= (current & 0x7F_00_00_00) >>> 3;
low |= (current & 0x7F_00_00) >>> 2;
low |= (current & 0x7F_00) >>> 1;
low |= (current & 0x7F) >>> 0;
low = low & ((1L << (end * 7)) - 1);
// high bits
if (zeros == 64) {
int last = block.getInt(blockOffset);
zeros = Integer.numberOfTrailingZeros(~last & INT_MASK);
end = (zeros + 1) / 8;
blockOffset += end;
high = (last & 0x7F_00) >>> 1;
high |= (last & 0x7F) >>> 0;
high = high & ((1 << (end * 7)) - 1);
if (end >= 3 || high > 0xFF) {
// only 63 - (55) = 8 bits allowed in high
throw new OrcCorruptionException(chunkLoader.getOrcDataSourceId(), "Decimal does not fit long (invalid table schema?)");
}
}
emitShortDecimal(result, count, low, high);
count++;
if (count == batchSize) {
return;
}
}
// handle the tail of the current block
count = decodeShortDecimalTail(result, count, batchSize);
}
}
use of io.trino.orc.OrcCorruptionException in project trino by trinodb.
the class UncompressedOrcChunkLoader method nextChunk.
@Override
public Slice nextChunk() throws IOException {
if (nextPosition >= dataReader.getSize()) {
throw new OrcCorruptionException(dataReader.getOrcDataSourceId(), "Read past end of stream");
}
Slice chunk = dataReader.seekBuffer(nextPosition);
dataReaderMemoryUsage.setBytes(dataReader.getRetainedSize());
lastCheckpoint = createInputStreamCheckpoint(0, nextPosition);
nextPosition += chunk.length();
return chunk;
}
use of io.trino.orc.OrcCorruptionException in project trino by trinodb.
the class UncompressedOrcChunkLoader method seekToCheckpoint.
@Override
public void seekToCheckpoint(long checkpoint) throws OrcCorruptionException {
int compressedOffset = decodeCompressedBlockOffset(checkpoint);
if (compressedOffset != 0) {
throw new OrcCorruptionException(dataReader.getOrcDataSourceId(), "Uncompressed stream does not support seeking to a compressed offset");
}
int decompressedOffset = decodeDecompressedOffset(checkpoint);
nextPosition = decompressedOffset;
lastCheckpoint = checkpoint;
}
use of io.trino.orc.OrcCorruptionException in project trino by trinodb.
the class OrcInputStream method readFully.
public void readFully(Slice buffer, int offset, int length) throws IOException {
while (length > 0) {
if (current != null && current.remaining() == 0) {
advance();
}
if (current == null) {
throw new OrcCorruptionException(chunkLoader.getOrcDataSourceId(), "Unexpected end of stream");
}
int chunkSize = min(length, (int) current.remaining());
current.readBytes(buffer, offset, chunkSize);
length -= chunkSize;
offset += chunkSize;
}
}
Aggregations