| 2120 | } |
| 2121 | |
| 2122 | int GetInternal(ByteArray* buffer, int max_values) { |
| 2123 | // Decode up to `max_values` strings into an internal buffer |
| 2124 | // and reference them into `buffer`. |
| 2125 | max_values = std::min(max_values, num_valid_values_); |
| 2126 | if (max_values == 0) { |
| 2127 | return max_values; |
| 2128 | } |
| 2129 | |
| 2130 | int suffix_read = suffix_decoder_.Decode(buffer, max_values); |
| 2131 | if (ARROW_PREDICT_FALSE(suffix_read != max_values)) { |
| 2132 | ParquetException::EofException("Read " + std::to_string(suffix_read) + |
| 2133 | ", expecting " + std::to_string(max_values) + |
| 2134 | " from suffix decoder"); |
| 2135 | } |
| 2136 | |
| 2137 | int64_t data_size = 0; |
| 2138 | const int32_t* prefix_len_ptr = |
| 2139 | buffered_prefix_length_->data_as<int32_t>() + prefix_len_offset_; |
| 2140 | for (int i = 0; i < max_values; ++i) { |
| 2141 | if (prefix_len_ptr[i] == 0) { |
| 2142 | // We don't need to copy the suffix if the prefix length is 0. |
| 2143 | continue; |
| 2144 | } |
| 2145 | if (ARROW_PREDICT_FALSE(prefix_len_ptr[i] < 0)) { |
| 2146 | throw ParquetException("negative prefix length in DELTA_BYTE_ARRAY"); |
| 2147 | } |
| 2148 | if (buffer[i].len == 0 && i != 0) { |
| 2149 | // We don't need to copy the prefix if the suffix length is 0 |
| 2150 | // and this is not the first run (that is, the prefix doesn't point |
| 2151 | // to the mutable `last_value_`). |
| 2152 | continue; |
| 2153 | } |
| 2154 | if (ARROW_PREDICT_FALSE(AddWithOverflow(data_size, prefix_len_ptr[i], &data_size) || |
| 2155 | AddWithOverflow(data_size, buffer[i].len, &data_size))) { |
| 2156 | throw ParquetException("excess expansion in DELTA_BYTE_ARRAY"); |
| 2157 | } |
| 2158 | } |
| 2159 | PARQUET_THROW_NOT_OK(buffered_data_->Resize(data_size)); |
| 2160 | |
| 2161 | std::string_view prefix{last_value_}; |
| 2162 | uint8_t* data_ptr = buffered_data_->mutable_data(); |
| 2163 | if (max_values > 0) { |
| 2164 | BuildBufferInternal</*is_first_run=*/true>(prefix_len_ptr, 0, buffer, &prefix, |
| 2165 | &data_ptr); |
| 2166 | } |
| 2167 | for (int i = 1; i < max_values; ++i) { |
| 2168 | BuildBufferInternal</*is_first_run=*/false>(prefix_len_ptr, i, buffer, &prefix, |
| 2169 | &data_ptr); |
| 2170 | } |
| 2171 | DCHECK_EQ(data_ptr - buffered_data_->mutable_data(), data_size); |
| 2172 | prefix_len_offset_ += max_values; |
| 2173 | this->num_values_ -= max_values; |
| 2174 | num_valid_values_ -= max_values; |
| 2175 | last_value_ = std::string{prefix}; |
| 2176 | |
| 2177 | if (num_valid_values_ == 0) { |
| 2178 | last_value_in_previous_page_ = last_value_; |
| 2179 | } |
nothing calls this directly
no test coverage detected