Compute the section of the file that should be read for the given row group and column chunk.
| 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 |
no test coverage detected