From 32413d33c0a156b307eee75fd3f7e706df208b6a Mon Sep 17 00:00:00 2001 From: Krisztian Szucs Date: Tue, 17 Dec 2024 10:08:08 +0100 Subject: [PATCH] use resize instead of reserve --- cpp/src/arrow/compute/kernels/scalar_hash.cc | 2 +- .../arrow/compute/kernels/scalar_hash_test.cc | 40 +++++++++++++++++-- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/cpp/src/arrow/compute/kernels/scalar_hash.cc b/cpp/src/arrow/compute/kernels/scalar_hash.cc index 554669abedeed..9dcfe16c3331e 100644 --- a/cpp/src/arrow/compute/kernels/scalar_hash.cc +++ b/cpp/src/arrow/compute/kernels/scalar_hash.cc @@ -120,7 +120,7 @@ struct FastHashScalar { if (type_id == Type::STRUCT) { std::vector> child_hashes(array.child_data.size()); - columns.reserve(array.child_data.size()); + columns.resize(array.child_data.size()); for (size_t i = 0; i < array.child_data.size(); i++) { auto child = array.child_data[i]; if (is_nested(child.type->id())) { diff --git a/cpp/src/arrow/compute/kernels/scalar_hash_test.cc b/cpp/src/arrow/compute/kernels/scalar_hash_test.cc index a2a2ce1ab69ab..f0aa13ff3339a 100644 --- a/cpp/src/arrow/compute/kernels/scalar_hash_test.cc +++ b/cpp/src/arrow/compute/kernels/scalar_hash_test.cc @@ -268,7 +268,7 @@ TEST_F(TestScalarHash, RandomNumericLike) { } } -TEST_F(TestScalarHash, RandomNested) { +TEST_F(TestScalarHash, RandomList) { auto rand = random::RandomArrayGenerator(kSeed); auto types = { list(int32()), @@ -282,9 +282,22 @@ TEST_F(TestScalarHash, RandomNested) { list(list(int16())), list(list(list(uint8()))), fixed_size_list(int32(), 3), - map(int32(), int32()), - map(int32(), utf8()), - map(utf8(), list(int16())), + }; + for (auto type : types) { + for (auto length : array_lengths) { + for (auto null_probability : null_probabilities) { + auto arr = rand.ArrayOf(type, length, null_probability); + CheckDeterminisic("hash32", arr); + CheckDeterminisic("hash64", arr); + } + } + } +} + +TEST_F(TestScalarHash, RandomStruct) { + auto rand = random::RandomArrayGenerator(kSeed); + auto types = { + struct_({field("f0", int32())}), struct_({field("f0", int32()), field("f1", utf8())}), struct_({field("f0", list(int32()))}), struct_({field("f0", struct_({field("f0", int32()), field("f1", utf8())}))}), @@ -300,5 +313,24 @@ TEST_F(TestScalarHash, RandomNested) { } } +TEST_F(TestScalarHash, RandomMap) { + auto rand = random::RandomArrayGenerator(kSeed); + auto types = { + map(int32(), int32()), + map(int32(), utf8()), + map(utf8(), list(int16())), + map(utf8(), map(int32(), int32())), + }; + for (auto type : types) { + for (auto length : array_lengths) { + for (auto null_probability : null_probabilities) { + auto arr = rand.ArrayOf(type, length, null_probability); + CheckDeterminisic("hash32", arr); + CheckDeterminisic("hash64", arr); + } + } + } +} + } // namespace compute } // namespace arrow