MCPcopy Create free account
hub / github.com/apache/arrow / ComputeColumnChunkRange

Function ComputeColumnChunkRange

cpp/src/parquet/file_reader.cc:176–213  ·  view source on GitHub ↗

Compute the section of the file that should be read for the given row group and column chunk.

Source from the content-addressed store, hash-verified

174/// Compute the section of the file that should be read for the given
175/// row group and column chunk.
176::arrow::io::ReadRange ComputeColumnChunkRange(FileMetaData* file_metadata,
177 int64_t source_size, int row_group_index,
178 int column_index) {
179 std::unique_ptr<RowGroupMetaData> row_group_metadata =
180 file_metadata->RowGroup(row_group_index);
181 std::unique_ptr<ColumnChunkMetaData> column_metadata =
182 row_group_metadata->ColumnChunk(column_index);
183
184 int64_t col_start = column_metadata->data_page_offset();
185 if (column_metadata->has_dictionary_page() &&
186 column_metadata->dictionary_page_offset() > 0 &&
187 col_start > column_metadata->dictionary_page_offset()) {
188 col_start = column_metadata->dictionary_page_offset();
189 }
190
191 int64_t col_length = column_metadata->total_compressed_size();
192 int64_t col_end;
193 if (col_start < 0 || col_length < 0) {
194 throw ParquetException("Invalid column metadata (corrupt file?)");
195 }
196
197 if (AddWithOverflow(col_start, col_length, &col_end) || col_end > source_size) {
198 throw ParquetException("Invalid column metadata (corrupt file?)");
199 }
200
201 // PARQUET-816 workaround for old files created by older parquet-mr
202 const ApplicationVersion& version = file_metadata->writer_version();
203 if (version.VersionLt(ApplicationVersion::PARQUET_816_FIXED_VERSION())) {
204 // The Parquet MR writer had a bug in 1.2.8 and below where it didn't include the
205 // dictionary page header size in total_compressed_size and total_uncompressed_size
206 // (see IMPALA-694). We add padding to compensate.
207 int64_t bytes_remaining = source_size - col_end;
208 int64_t padding = std::min<int64_t>(kMaxDictHeaderSize, bytes_remaining);
209 col_length += padding;
210 }
211
212 return {col_start, col_length};
213}
214
215} // namespace
216

Callers 4

GetColumnPageReaderMethod · 0.85
PreBufferMethod · 0.85
GetReadRangesMethod · 0.85
WhenBufferedMethod · 0.85

Calls 10

ParquetExceptionFunction · 0.85
AddWithOverflowFunction · 0.85
writer_versionMethod · 0.80
VersionLtMethod · 0.80
RowGroupMethod · 0.45
ColumnChunkMethod · 0.45
data_page_offsetMethod · 0.45
has_dictionary_pageMethod · 0.45
total_compressed_sizeMethod · 0.45

Tested by

no test coverage detected