Skip to content

Commit 99b3b0a

Browse files
pitrouwesm
authored andcommitted
PARQUET-1463: [C++] Utilize common hashing machinery for dictionary encoding
Author: Antoine Pitrou <antoine@python.org> Closes #3036 from pitrou/PARQUET-1463-hashing-refactor and squashes the following commits: 3c12c88 <Antoine Pitrou> PARQUET-1463: Utilize common hashing machinery for dictionary encoding
1 parent 13c63bd commit 99b3b0a

4 files changed

Lines changed: 98 additions & 223 deletions

File tree

cpp/src/arrow/util/hashing-test.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,14 @@ TEST(BinaryMemoTable, Basics) {
370370
table.CopyValues(4 /* start offset */, reinterpret_cast<uint8_t*>(&values[0]));
371371
ASSERT_EQ(values, expected_values);
372372
}
373+
{
374+
std::vector<std::string> expected({B, C, D, E, F});
375+
std::vector<std::string> actual;
376+
table.VisitValues(1 /* start offset */, [&](const util::string_view& v) {
377+
actual.emplace_back(v.data(), v.length());
378+
});
379+
ASSERT_EQ(actual, expected);
380+
}
373381
}
374382

375383
TEST(BinaryMemoTable, Stress) {

cpp/src/arrow/util/hashing.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include "arrow/array.h"
3636
#include "arrow/buffer.h"
37+
#include "arrow/builder.h"
3738
#include "arrow/type.h"
3839
#include "arrow/type_traits.h"
3940
#include "arrow/util/bit-util.h"
@@ -605,6 +606,17 @@ class BinaryMemoTable {
605606
CopyValues(0, out_size, out_data);
606607
}
607608

609+
// Visit the stored values in insertion order.
610+
// The visitor function should have the signature `void(util::string_view)`
611+
// or `void(const util::string_view&)`.
612+
template <typename VisitFunc>
613+
void VisitValues(int32_t start, VisitFunc&& visit) const {
614+
for (uint32_t i = start; i < offsets_.size() - 1; ++i) {
615+
visit(
616+
util::string_view(values_.data() + offsets_[i], offsets_[i + 1] - offsets_[i]));
617+
}
618+
}
619+
608620
protected:
609621
struct Payload {
610622
int32_t memo_index;

cpp/src/parquet/encoding-benchmark.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ static void DecodeDict(std::vector<typename Type::c_type>& values,
110110

111111
DictEncoder<Type> encoder(descr.get(), &pool, allocator);
112112
for (int i = 0; i < num_values; ++i) {
113-
// No SSE
114-
encoder.template Put<false>(values[i]);
113+
encoder.Put(values[i]);
115114
}
116115

117116
std::shared_ptr<ResizableBuffer> dict_buffer =

0 commit comments

Comments
 (0)