MCPcopy Create free account
hub / github.com/apache/impala / DeltaEncode

Function DeltaEncode

be/src/util/bit-packing-test.cc:339–376  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

337
338template <typename ParquetType>
339DeltaData<ParquetType> DeltaEncode(const std::vector<ParquetType>& input, int bit_width) {
340 using UnsignedParquetType = typename std::make_unsigned<ParquetType>::type;
341 const ParquetType base_value = input.empty() ? 0 : input[0];
342 std::vector<ParquetType> deltas;
343
344 /// Calculate the deltas.
345 for (int i = 1; i < input.size(); i++) {
346 UnsignedParquetType current = input[i];
347 UnsignedParquetType previous = input[i - 1];
348 ParquetType delta = current - previous;
349 deltas.push_back(delta);
350 }
351
352 /// Offset the deltas.
353 const auto it = std::min_element(deltas.begin(), deltas.end());
354 const ParquetType min_delta = (it == deltas.end()) ? 0 : *it;
355
356 std::for_each(deltas.begin(), deltas.end(), [min_delta](ParquetType& element) {
357 element = ArithmeticUtil::AsUnsigned<std::minus>(element, min_delta);
358 });
359
360 // Bit pack the deltas.
361 const int bytes_required = BitUtil::RoundUpNumBytes(bit_width * deltas.size());
362 std::vector<uint8_t> out_data(bytes_required);
363
364 if (bytes_required > 0) {
365 BitWriter writer(out_data.data(), bytes_required);
366 if (bit_width > 0) {
367 for (const ParquetType delta : deltas) {
368 const UnsignedParquetType delta_unsigned = delta;
369 EXPECT_TRUE(writer.PutValue(delta_unsigned, bit_width));
370 }
371 }
372 writer.Flush();
373 }
374
375 return DeltaData<ParquetType>(base_value, min_delta, deltas.size(), out_data);
376}
377
378template <typename INT_T, typename ParquetType>
379void RandomUnpackAndDeltaDecodeTest() {

Callers

nothing calls this directly

Calls 8

push_backMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
dataMethod · 0.45
PutValueMethod · 0.45
FlushMethod · 0.45

Tested by

no test coverage detected