You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "albertlockett (via GitHub)" <gi...@apache.org> on 2025/06/05 12:58:32 UTC
[I] Add efficient way to change the keys of a dictionary builder [arrow-rs]
albertlockett opened a new issue, #7610:
URL: https://github.com/apache/arrow-rs/issues/7610
**Is your feature request related to a problem or challenge? Please describe what you are trying to do.**
<!--
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
(This section helps Arrow developers understand the context and *why* for this feature, in addition to the *what*)
-->
I'm working on a feature where we try to construct an array using the smallest key type possible. As part of my logic, when we add a value to the array, and receive a `DictionaryKeyOverflowError`, I'd like to then change to a builder with a bigger key type.
**Describe the solution you'd like**
<!--
A clear and concise description of what you want to happen.
-->
I'd like this dictionary upgrade to be efficient and avoid unnecessary copies.
I'd like to be able to construct a new builder that uses the same values & other internal builder state, but a new builder for the keys.
**Describe alternatives you've considered**
<!--
A clear and concise description of any alternative solutions or features you've considered.
-->
Constructing the dictionary array and copying everything into a new builder. This seems less efficient:
```rs
let mut u8_keyed_dict_builder = StringDictionaryBuilder::<UInt8Type>::new();
let _ = u8_keyed_dict_builder.append("val 0");
let _ = u8_keyed_dict_builder.append("val 1");
// ... append 254 more values
// ... eventually I realize the dict will overflow ...
// .. upgrade to builder keyed by UInt16 ...
let u8_keyed_dict = u8_keyed_dict_builder.finish_cloned();
let cast_result = cast(
&u8_keyed_dict,
&DataType::Dictionary(Box::new(DataType::UInt16), Box::new(DataType::Utf8)),
)
.unwrap();
let casted_dict = cast_result
.as_any()
.downcast_ref::<DictionaryArray<UInt16Type>>()
.unwrap();
let typed_dict = casted_dict.downcast_dict::<StringArray>().unwrap();
let mut u16_keyed_dict_builder = StringDictionaryBuilder::<UInt16Type>::new();
u16_keyed_dict_builder
// this copies values
.extend_dictionary(&typed_dict)
.unwrap();
```
**Additional context**
<!--
Add any other context or screenshots about the feature request here.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Add efficient way to change the keys of string dictionary builder [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb closed issue #7610: Add efficient way to change the keys of string dictionary builder
URL: https://github.com/apache/arrow-rs/issues/7610
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Add efficient way to change the keys of string dictionary builder [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on issue #7610:
URL: https://github.com/apache/arrow-rs/issues/7610#issuecomment-2992675810
`label_issue.py` automatically added labels {'arrow'} from #7611
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org