This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new e6977de3be fix: invoke `AsRef` once in bytes dictionary builder
(#12463)
e6977de3be is described below
commit e6977de3be516490a7668b8187f9c11368d5ea71
Author: compiler-segfault <[email protected]>
AuthorDate: Thu Nov 26 10:19:47 2026 +0000
fix: invoke `AsRef` once in bytes dictionary builder (#12463)
Fixes #12424.
`GenericByteDictionaryBuilder::get_or_insert_key` hashed
`value.as_ref()` to look the value up, then called `value.as_ref()` a
second time inside the insert closure through
`storage.append_value(value)`. `AsRef` is not required to be idempotent,
so the stored bytes could differ from the bytes that were hashed: the
dictionary then holds a value filed under the wrong hash, and a later
append of the value that was actually hashed adds a duplicate entry.
The builder now stores the same `&T::Native` that it hashed. This is the
same fix #12397 made for `FixedSizeBinaryDictionaryBuilder`, which had
the identical pattern.
Verification:
- New test `test_dictionary_builder_hashes_and_stores_the_same_bytes`
uses an `AsRef<str>` that returns a different value on each call; on
`main` it fails with `left: 2, right: 1` (the dictionary ends up with
two entries and keys `[0, 1]` instead of one entry with `[0, 0]`). It
passes with this change.
- `cargo test -p arrow-array`: 767 passed, 1 ignored.
- `cargo fmt --all -- --check` and `cargo clippy -p arrow-array
--all-targets --all-features -- -D warnings` are clean.
The text above was drafted with an AI assistant; I ran the tests myself.
Co-authored-by: compiler-segfault
<[email protected]>
---
arrow-array/src/builder/generic_bytes_dictionary_builder.rs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arrow-array/src/builder/generic_bytes_dictionary_builder.rs
b/arrow-array/src/builder/generic_bytes_dictionary_builder.rs
index 32dcb743a9..cfde189b74 100644
--- a/arrow-array/src/builder/generic_bytes_dictionary_builder.rs
+++ b/arrow-array/src/builder/generic_bytes_dictionary_builder.rs
@@ -259,8 +259,8 @@ where
T: ByteArrayType,
{
fn get_or_insert_key(&mut self, value: impl AsRef<T::Native>) ->
Result<K::Native, ArrowError> {
- let value_native: &T::Native = value.as_ref();
- let value_bytes: &[u8] = value_native.as_ref();
+ let value: &T::Native = value.as_ref();
+ let value_bytes: &[u8] = value.as_ref();
let state = &self.state;
let storage = &mut self.values_builder;