Skip to content

Commit

Permalink
use resize instead of reserve
Browse files Browse the repository at this point in the history
  • Loading branch information
kszucs committed Dec 17, 2024
1 parent 0733ae9 commit 32413d3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cpp/src/arrow/compute/kernels/scalar_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ struct FastHashScalar {

if (type_id == Type::STRUCT) {
std::vector<std::shared_ptr<ArrayData>> 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())) {
Expand Down
40 changes: 36 additions & 4 deletions cpp/src/arrow/compute/kernels/scalar_hash_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand All @@ -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())}))}),
Expand All @@ -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

0 comments on commit 32413d3

Please sign in to comment.