Search in sources :

Example 6 with OrcCorruptionException

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;
}
Also used : OrcCorruptionException(io.trino.orc.OrcCorruptionException) DecimalStreamCheckpoint(io.trino.orc.checkpoint.DecimalStreamCheckpoint)

Example 7 with OrcCorruptionException

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);
    }
}
Also used : OrcCorruptionException(io.trino.orc.OrcCorruptionException) DecimalStreamCheckpoint(io.trino.orc.checkpoint.DecimalStreamCheckpoint)

Example 8 with OrcCorruptionException

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;
}
Also used : Slice(io.airlift.slice.Slice) OrcCorruptionException(io.trino.orc.OrcCorruptionException)

Example 9 with OrcCorruptionException

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;
}
Also used : OrcCorruptionException(io.trino.orc.OrcCorruptionException) InputStreamCheckpoint.createInputStreamCheckpoint(io.trino.orc.checkpoint.InputStreamCheckpoint.createInputStreamCheckpoint)

Example 10 with OrcCorruptionException

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;
    }
}
Also used : OrcCorruptionException(io.trino.orc.OrcCorruptionException) InputStreamCheckpoint.createInputStreamCheckpoint(io.trino.orc.checkpoint.InputStreamCheckpoint.createInputStreamCheckpoint)

Aggregations

OrcCorruptionException (io.trino.orc.OrcCorruptionException)33 Block (io.trino.spi.block.Block)13 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)11 LongStreamCheckpoint (io.trino.orc.checkpoint.LongStreamCheckpoint)7 DecimalStreamCheckpoint (io.trino.orc.checkpoint.DecimalStreamCheckpoint)4 InputStreamCheckpoint.createInputStreamCheckpoint (io.trino.orc.checkpoint.InputStreamCheckpoint.createInputStreamCheckpoint)4 LongStreamV2Checkpoint (io.trino.orc.checkpoint.LongStreamV2Checkpoint)4 ByteArrayBlock (io.trino.spi.block.ByteArrayBlock)4 LongArrayBlock (io.trino.spi.block.LongArrayBlock)4 Slice (io.airlift.slice.Slice)3 LongStreamV1Checkpoint (io.trino.orc.checkpoint.LongStreamV1Checkpoint)3 ByteStreamCheckpoint (io.trino.orc.checkpoint.ByteStreamCheckpoint)2 ReaderUtils.verifyStreamType (io.trino.orc.reader.ReaderUtils.verifyStreamType)2 IntArrayBlock (io.trino.spi.block.IntArrayBlock)2 LazyBlock (io.trino.spi.block.LazyBlock)2 RowBlock (io.trino.spi.block.RowBlock)2 VariableWidthBlock (io.trino.spi.block.VariableWidthBlock)2 RowType (io.trino.spi.type.RowType)2 Type (io.trino.spi.type.Type)2 ColumnReaders.createColumnReader (io.trino.orc.reader.ColumnReaders.createColumnReader)1