Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions cpp/src/arrow/array/array_dict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,8 @@ DictionaryArray::DictionaryArray(const std::shared_ptr<DataType>& type,
}

const std::shared_ptr<Array>& DictionaryArray::dictionary() const {
if (!dictionary_) {
// TODO(GH-36503) this isn't thread safe
dictionary_ = MakeArray(data_->dictionary);
}
std::call_once(dictionary_init_flag_,
[this]() { dictionary_ = MakeArray(data_->dictionary); });
return dictionary_;
}

Expand Down
5 changes: 4 additions & 1 deletion cpp/src/arrow/array/array_dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <cstdint>
#include <memory>
#include <mutex>

#include "arrow/array/array_base.h"
#include "arrow/array/data.h"
Expand Down Expand Up @@ -118,8 +119,10 @@ class ARROW_EXPORT DictionaryArray : public Array {
const DictionaryType* dict_type_;
std::shared_ptr<Array> indices_;

// Lazily initialized when invoking dictionary()
// Lazily initialized when invoking dictionary().
// Thread-safe initialization is ensured by dictionary_init_flag_.
mutable std::shared_ptr<Array> dictionary_;
mutable std::once_flag dictionary_init_flag_;
};

/// \brief Helper class for incremental dictionary unification
Expand Down
Loading