Repository navigation
minor: drive-by refactors for dicts in substring & filter - #10264
Conversation
| // Keys were valid before, filtered subset is therefore still valid | ||
| DictionaryArray::from(unsafe { builder.build_unchecked() }) | ||
| let new_keys = filter_primitive(array.keys(), predicate); | ||
| unsafe { DictionaryArray::new_unchecked(new_keys, array.values().clone()) } |
There was a problem hiding this comment.
see
arrow-rs/arrow-select/src/take.rs
Lines 934 to 940 in 32bba5a
There was a problem hiding this comment.
yeah, this is much nicer (and will save a few small allocations, etc)
| UInt64: UInt64Type | ||
| ) | ||
| DataType::Dictionary(_, _) => { | ||
| let dictionary = array.as_any_dictionary(); |
There was a problem hiding this comment.
nice win to use as_any_dictionary() here to dynamically dispatch since we dont need the keys
(i asked codex to look for other places to do this, but the places it identified seemed unsuitable as they still needed keys; so i guess this was the last easy win for this type of refactor)
| Ok(Arc::new(dictionary.with_values(values))) | ||
| } | ||
| DataType::LargeBinary => { | ||
| byte_substring(array.as_binary::<i64>(), start, length.map(|e| e as i64)) |
There was a problem hiding this comment.
here just using the more ergonomic as_binary() etc. cast methods
| ) | ||
| fixed_size_binary_substring(array.as_fixed_size_binary(), old_len, start, length) | ||
| } | ||
| DataType::LargeUtf8 => { |
There was a problem hiding this comment.
i notice we dont actually support views here; i suppose can raise that as a separate issue
There was a problem hiding this comment.
Though dictionaries of views is likely not super common (as a StringView/ButeView is pretty close to a dictionary already)
There was a problem hiding this comment.
ah i meant the regular path (since this is not only for dict encoded)
| // Keys were valid before, filtered subset is therefore still valid | ||
| DictionaryArray::from(unsafe { builder.build_unchecked() }) | ||
| let new_keys = filter_primitive(array.keys(), predicate); | ||
| unsafe { DictionaryArray::new_unchecked(new_keys, array.values().clone()) } |
There was a problem hiding this comment.
yeah, this is much nicer (and will save a few small allocations, etc)
| ) | ||
| fixed_size_binary_substring(array.as_fixed_size_binary(), old_len, start, length) | ||
| } | ||
| DataType::LargeUtf8 => { |
There was a problem hiding this comment.
Though dictionaries of views is likely not super common (as a StringView/ButeView is pretty close to a dictionary already)
Which issue does this PR close?
ArrayDatawith direct Array construction, when possible #9298Rationale for this change
Some drive-by simplifications whilst I was checking some parts of the codebase.
What changes are included in this PR?
In substring utilize
as_any_dictionary()to cut down on lines of code (and also codegen)In filter, follow similar approach to take when reconstructing a dictionary
Are these changes tested?
Existing tests
Are there any user-facing changes?
No