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

Method FlushBlock

cpp/src/parquet/encoder.cc:1143–1209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1141
1142template <typename DType>
1143void DeltaBitPackEncoder<DType>::FlushBlock() {
1144 if (values_current_block_ == 0) {
1145 return;
1146 }
1147
1148 // Calculate the frame of reference for this miniblock. This value will be subtracted
1149 // from all deltas to guarantee all deltas are positive for encoding.
1150 const T min_delta =
1151 *std::min_element(deltas_.begin(), deltas_.begin() + values_current_block_);
1152 bit_writer_.PutZigZagVlqInt(min_delta);
1153
1154 // Call to GetNextBytePtr reserves mini_blocks_per_block_ bytes of space to write
1155 // bit widths of miniblocks as they become known during the encoding.
1156 uint8_t* bit_width_data = bit_writer_.GetNextBytePtr(mini_blocks_per_block_);
1157 DCHECK(bit_width_data != nullptr);
1158
1159 const uint32_t num_miniblocks =
1160 static_cast<uint32_t>(std::ceil(static_cast<double>(values_current_block_) /
1161 static_cast<double>(values_per_mini_block_)));
1162 for (uint32_t i = 0; i < num_miniblocks; i++) {
1163 const uint32_t values_current_mini_block =
1164 std::min(values_per_mini_block_, values_current_block_);
1165
1166 const uint32_t start = i * values_per_mini_block_;
1167 const T max_delta = *std::max_element(
1168 deltas_.begin() + start, deltas_.begin() + start + values_current_mini_block);
1169
1170 // The minimum number of bits required to write any of values in deltas_ vector.
1171 // See overflow comment above.
1172 // TODO: We can remove this condition once CRAN upgrades its macOS
1173 // SDK from 11.3.
1174 // __apple_build_version__ should be defined only on Apple clang
1175#if defined(__apple_build_version__) && !defined(__cpp_lib_bitops)
1176 const auto bit_width = bit_width_data[i] =
1177 std::log2p1(static_cast<UT>(max_delta) - static_cast<UT>(min_delta));
1178#else
1179 const auto bit_width = bit_width_data[i] =
1180 std::bit_width(static_cast<UT>(max_delta) - static_cast<UT>(min_delta));
1181#endif
1182
1183 for (uint32_t j = start; j < start + values_current_mini_block; j++) {
1184 // Convert delta to frame of reference. See overflow comment above.
1185 const UT value = static_cast<UT>(deltas_[j]) - static_cast<UT>(min_delta);
1186 bit_writer_.PutValue(value, bit_width);
1187 }
1188 // If there are not enough values to fill the last mini block, we pad the mini block
1189 // with zeroes so that its length is the number of values in a full mini block
1190 // multiplied by the bit width.
1191 for (uint32_t j = values_current_mini_block; j < values_per_mini_block_; j++) {
1192 bit_writer_.PutValue(0, bit_width);
1193 }
1194 values_current_block_ -= values_current_mini_block;
1195 }
1196
1197 // If, in the last block, less than <number of miniblocks in a block> miniblocks are
1198 // needed to store the values, the bytes storing the bit widths of the unneeded
1199 // miniblocks are still present, their value should be zero, but readers must accept
1200 // arbitrary values as well.

Callers

nothing calls this directly

Calls 10

PutZigZagVlqIntMethod · 0.80
GetNextBytePtrMethod · 0.80
PutValueMethod · 0.80
bytes_writtenMethod · 0.80
bit_widthFunction · 0.50
beginMethod · 0.45
FlushMethod · 0.45
AppendMethod · 0.45
bufferMethod · 0.45
ClearMethod · 0.45

Tested by

no test coverage detected