Search in sources :

Example 1 with CompressionKind

use of org.apache.orc.CompressionKind in project hive by apache.

the class OrcEncodedDataReader method getStripeFooterFromCacheOrDisk.

private OrcProto.StripeFooter getStripeFooterFromCacheOrDisk(StripeInformation si, OrcBatchKey stripeKey) throws IOException {
    boolean hasCache = fileKey != null && metadataCache != null;
    if (hasCache) {
        LlapBufferOrBuffers footerBuffers = metadataCache.getStripeTail(stripeKey);
        if (footerBuffers != null) {
            try {
                counters.incrCounter(LlapIOCounters.METADATA_CACHE_HIT);
                ensureCodecFromFileMetadata();
                MemoryBuffer footerBuffer = footerBuffers.getSingleBuffer();
                if (footerBuffer != null) {
                    ByteBuffer bb = footerBuffer.getByteBufferDup();
                    return buildStripeFooter(new BufferChunk(bb, 0), bb.remaining(), codec, fileMetadata.getCompressionBufferSize());
                } else {
                    MemoryBuffer[] footerBufferArray = footerBuffers.getMultipleBuffers();
                    int pos = 0;
                    BufferChunkList bcs = new BufferChunkList();
                    for (MemoryBuffer buf : footerBufferArray) {
                        ByteBuffer bb = buf.getByteBufferDup();
                        bcs.add(new BufferChunk(bb, pos));
                        pos += bb.remaining();
                    }
                    return buildStripeFooter(bcs.get(), pos, codec, fileMetadata.getCompressionBufferSize());
                }
            } finally {
                metadataCache.decRefBuffer(footerBuffers);
            }
        }
        counters.incrCounter(LlapIOCounters.METADATA_CACHE_MISS);
        throwIfCacheOnlyRead(isReadCacheOnly);
    }
    long offset = si.getOffset() + si.getIndexLength() + si.getDataLength();
    long startTime = counters.startTimeCounter();
    ensureRawDataReader(true);
    // TODO: add this to metadatareader in ORC - SI => metadata buffer, not just metadata.
    if (LOG.isTraceEnabled()) {
        LOG.trace("Reading [" + offset + ", " + (offset + si.getFooterLength()) + ") based on " + si);
    }
    DiskRangeList footerRange = rawDataReader.readFileData(new DiskRangeList(offset, offset + si.getFooterLength()), 0, false);
    // LOG.error("Got " + RecordReaderUtils.stringifyDiskRanges(footerRange));
    counters.incrWallClockCounter(LlapIOCounters.HDFS_TIME_NS, startTime);
    // Can only happens w/zcr for a single input buffer.
    assert footerRange.next == null;
    if (hasCache) {
        LlapBufferOrBuffers cacheBuf = metadataCache.putStripeTail(stripeKey, footerRange.getData().duplicate(), cacheTag, isStopped);
        // We don't use this one.
        metadataCache.decRefBuffer(cacheBuf);
    }
    ByteBuffer bb = footerRange.getData().duplicate();
    CompressionKind kind = orcReader.getCompressionKind();
    boolean isPool = useCodecPool;
    CompressionCodec codec = isPool ? OrcCodecPool.getCodec(kind) : WriterImpl.createCodec(kind);
    boolean isCodecError = true;
    try {
        OrcProto.StripeFooter result = buildStripeFooter(new BufferChunk(bb, 0), bb.remaining(), codec, orcReader.getCompressionSize());
        isCodecError = false;
        return result;
    } finally {
        try {
            if (codec != null) {
                if (isPool && !isCodecError) {
                    OrcCodecPool.returnCodec(kind, codec);
                } else {
                    codec.close();
                }
            }
        } catch (Exception ex) {
            LOG.error("Ignoring codec cleanup error", ex);
        }
    }
}
Also used : CompressionKind(org.apache.orc.CompressionKind) DiskRangeList(org.apache.hadoop.hive.common.io.DiskRangeList) OrcProto(org.apache.orc.OrcProto) BufferChunk(org.apache.orc.impl.BufferChunk) ByteBuffer(java.nio.ByteBuffer) IllegalCacheConfigurationException(org.apache.hadoop.hive.llap.IllegalCacheConfigurationException) IOException(java.io.IOException) MemoryBuffer(org.apache.hadoop.hive.common.io.encoded.MemoryBuffer) BufferChunkList(org.apache.orc.impl.BufferChunkList) CompressionCodec(org.apache.orc.CompressionCodec) LlapBufferOrBuffers(org.apache.hadoop.hive.llap.io.metadata.MetadataCache.LlapBufferOrBuffers)

Example 2 with CompressionKind

use of org.apache.orc.CompressionKind in project hive by apache.

the class OrcEncodedDataReader method getStripeStatsFromOrcTail.

/**
 * Convenience method to retrieve StripeStatic from an existing OrcTail without create a new Reader.
 *
 * @param orcTail The existing OrcTail from metadataCache
 * @return StripeStatistics
 * @throws IOException
 */
private static List<OrcProto.StripeStatistics> getStripeStatsFromOrcTail(OrcTail orcTail) throws IOException {
    CompressionKind compressionKind = orcTail.getCompressionKind();
    InStream.StreamOptions options = null;
    if (compressionKind != CompressionKind.NONE) {
        options = InStream.options().withCodec(OrcCodecPool.getCodec(compressionKind)).withBufferSize(orcTail.getCompressionBufferSize());
    }
    InStream stream = InStream.create(STRIPE_STATS_STREAM, orcTail.getTailBuffer(), orcTail.getMetadataOffset(), orcTail.getMetadataSize(), options);
    return OrcProto.Metadata.parseFrom(InStream.createCodedInputStream(stream)).getStripeStatsList();
}
Also used : CompressionKind(org.apache.orc.CompressionKind) InStream(org.apache.orc.impl.InStream)

Aggregations

CompressionKind (org.apache.orc.CompressionKind)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 DiskRangeList (org.apache.hadoop.hive.common.io.DiskRangeList)1 MemoryBuffer (org.apache.hadoop.hive.common.io.encoded.MemoryBuffer)1 IllegalCacheConfigurationException (org.apache.hadoop.hive.llap.IllegalCacheConfigurationException)1 LlapBufferOrBuffers (org.apache.hadoop.hive.llap.io.metadata.MetadataCache.LlapBufferOrBuffers)1 CompressionCodec (org.apache.orc.CompressionCodec)1 OrcProto (org.apache.orc.OrcProto)1 BufferChunk (org.apache.orc.impl.BufferChunk)1 BufferChunkList (org.apache.orc.impl.BufferChunkList)1 InStream (org.apache.orc.impl.InStream)1