pitrou commented on a change in pull request #8050:
URL: https://github.com/apache/arrow/pull/8050#discussion_r482854105
##########
File path: cpp/src/arrow/ipc/dictionary.cc
##########
@@ -143,10 +143,43 @@ int DictionaryFieldMapper::num_fields() const { return
impl_->num_fields(); }
// DictionaryMemo implementation
struct DictionaryMemo::Impl {
- // Map of dictionary id to dictionary array
- std::unordered_map<int64_t, std::shared_ptr<ArrayData>> id_to_dictionary_;
+ // Map of dictionary id to dictionary array(s) (several in case of deltas)
+ std::unordered_map<int64_t, ArrayDataVector> id_to_dictionary_;
std::unordered_map<int64_t, std::shared_ptr<DataType>> id_to_type_;
DictionaryFieldMapper mapper_;
+
+ Result<decltype(id_to_dictionary_)::iterator> FindDictionary(int64_t id) {
+ auto it = id_to_dictionary_.find(id);
+ if (it == id_to_dictionary_.end()) {
+ return Status::KeyError("Dictionary with id ", id, " not found");
+ }
+ return it;
+ }
+
+ Result<std::shared_ptr<ArrayData>> ReifyDictionary(int64_t id, MemoryPool*
pool) {
+ ARROW_ASSIGN_OR_RAISE(auto it, FindDictionary(id));
+ ArrayDataVector* data_vector = &it->second;
+
+ DCHECK(!data_vector->empty());
+ if (data_vector->size() > 1) {
+ // There are deltas, we need to concatenate them to the first dictionary.
+ ArrayVector to_combine;
+ to_combine.reserve(data_vector->size());
+ // IMPORTANT: At this point, the dictionary data may be untrusted.
+ // We need to validate it, as concatenation can crash on invalid or
+ // corrupted data. Full validation is necessary for certain types
+ // (for example nested dictionaries).
Review comment:
Well, primitive types have O(1) full validation, so I don't think a fast
branch would change anything.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]