| 80 | } |
| 81 | |
| 82 | std::unique_ptr<SeekableInputStream> StripeStreamsImpl::getStream(uint64_t columnId, |
| 83 | proto::Stream_Kind kind, |
| 84 | bool shouldStream) const { |
| 85 | uint64_t offset = stripeStart_; |
| 86 | uint64_t dataEnd = |
| 87 | stripeInfo_.offset() + stripeInfo_.index_length() + stripeInfo_.data_length(); |
| 88 | MemoryPool* pool = reader_.getFileContents().pool; |
| 89 | for (int i = 0; i < footer_.streams_size(); ++i) { |
| 90 | const proto::Stream& stream = footer_.streams(i); |
| 91 | if (stream.has_kind() && stream.kind() == kind && |
| 92 | stream.column() == static_cast<uint64_t>(columnId)) { |
| 93 | uint64_t streamLength = stream.length(); |
| 94 | if (offset + streamLength > dataEnd) { |
| 95 | std::stringstream msg; |
| 96 | msg << "Malformed stream meta at stream index " << i << " in stripe " << stripeIndex_ |
| 97 | << ": streamOffset=" << offset << ", streamLength=" << streamLength |
| 98 | << ", stripeOffset=" << stripeInfo_.offset() |
| 99 | << ", stripeIndexLength=" << stripeInfo_.index_length() |
| 100 | << ", stripeDataLength=" << stripeInfo_.data_length(); |
| 101 | throw ParseError(msg.str()); |
| 102 | } |
| 103 | |
| 104 | BufferSlice slice; |
| 105 | if (readCache_) { |
| 106 | ReadRange range{offset, streamLength}; |
| 107 | slice = readCache_->read(range); |
| 108 | } |
| 109 | |
| 110 | uint64_t myBlock = shouldStream ? input_.getNaturalReadSize() : streamLength; |
| 111 | std::unique_ptr<SeekableInputStream> seekableInput; |
| 112 | if (slice.buffer) { |
| 113 | seekableInput = std::make_unique<SeekableArrayInputStream>( |
| 114 | slice.buffer->data() + slice.offset, slice.length); |
| 115 | } else { |
| 116 | seekableInput = std::make_unique<SeekableFileInputStream>(&input_, offset, streamLength, |
| 117 | *pool, myBlock); |
| 118 | } |
| 119 | return createDecompressor(reader_.getCompression(), std::move(seekableInput), |
| 120 | reader_.getCompressionSize(), *pool, |
| 121 | reader_.getFileContents().readerMetrics); |
| 122 | } |
| 123 | offset += stream.length(); |
| 124 | } |
| 125 | return nullptr; |
| 126 | } |
| 127 | |
| 128 | MemoryPool& StripeStreamsImpl::getMemoryPool() const { |
| 129 | return *reader_.getFileContents().pool; |
no test coverage detected