use of org.apache.orc.OrcProto.FileTail in project hive by apache.
the class OrcEncodedDataReader method getFileFooterFromCacheOrDisk.
/**
* Gets file metadata for the split from cache, or reads it from the file.
*/
private OrcFileMetadata getFileFooterFromCacheOrDisk() throws IOException {
LlapBufferOrBuffers tailBuffers = null;
List<StripeStatistics> stats = null;
List<StripeInformation> stripes = null;
boolean hasCache = fileKey != null && metadataCache != null;
if (hasCache) {
tailBuffers = metadataCache.getFileMetadata(fileKey);
if (tailBuffers != null) {
try {
OrcTail orcTail = getOrcTailFromLlapBuffers(tailBuffers);
counters.incrCounter(LlapIOCounters.METADATA_CACHE_HIT);
FileTail tail = orcTail.getFileTail();
stats = getStripeStatsFromOrcTail(orcTail);
stripes = new ArrayList<>(tail.getFooter().getStripesCount());
int stripeIdx = 0;
for (OrcProto.StripeInformation stripeProto : tail.getFooter().getStripesList()) {
stripes.add(new ReaderImpl.StripeInformationImpl(stripeProto, stripeIdx++, -1, null));
}
return new OrcFileMetadata(fileKey, tail.getFooter(), tail.getPostscript(), stats, stripes, ReaderImpl.getFileVersion(tail.getPostscript().getVersionList()));
} finally {
// We don't need the buffer anymore.
metadataCache.decRefBuffer(tailBuffers);
}
} else {
counters.incrCounter(LlapIOCounters.METADATA_CACHE_MISS);
throwIfCacheOnlyRead(isReadCacheOnly);
}
}
ensureOrcReader();
ByteBuffer tailBufferBb = orcReader.getSerializedFileFooter();
if (hasCache) {
tailBuffers = metadataCache.putFileMetadata(fileKey, tailBufferBb, cacheTag, isStopped);
// We don't use the cache's copy of the buffer.
metadataCache.decRefBuffer(tailBuffers);
}
FileTail ft = orcReader.getFileTail();
return new OrcFileMetadata(fileKey, ft.getFooter(), ft.getPostscript(), orcReader.getOrcProtoStripeStatistics(), orcReader.getStripes(), orcReader.getFileVersion());
}
Aggregations