MCPcopy Create free account
hub / github.com/apache/arrow / Converter_Dictionary

Method Converter_Dictionary

r/src/array_to_vector.cpp:571–615  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

569
570 public:
571 explicit Converter_Dictionary(const std::shared_ptr<ChunkedArray>& chunked_array)
572 : Converter(chunked_array),
573 need_unification_(DictionaryChunkArrayNeedUnification(chunked_array)) {
574 if (need_unification_) {
575 const auto& arr_type = checked_cast<const DictionaryType&>(*chunked_array->type());
576 unifier_ = ValueOrStop(DictionaryUnifier::Make(arr_type.value_type()));
577
578 int n_arrays = chunked_array->num_chunks();
579 arrays_transpose_.resize(n_arrays);
580
581 for (int i = 0; i < n_arrays; i++) {
582 const auto& dict_i =
583 *checked_cast<const DictionaryArray&>(*chunked_array->chunk(i)).dictionary();
584 StopIfNotOk(unifier_->Unify(dict_i, &arrays_transpose_[i]));
585 }
586
587 StopIfNotOk(unifier_->GetResult(&out_type_, &dictionary_));
588 } else {
589 const auto& dict_type = checked_cast<const DictionaryType&>(*chunked_array->type());
590
591 const auto& indices_type = *dict_type.index_type();
592 switch (indices_type.id()) {
593 case Type::UINT8:
594 case Type::INT8:
595 case Type::UINT16:
596 case Type::INT16:
597 case Type::INT32:
598 // TODO: also add int64, uint32, uint64 downcasts, if possible
599 break;
600 default:
601 cpp11::stop("Cannot convert Dictionary Array of type `%s` to R",
602 dict_type.ToString().c_str());
603 }
604
605 if (chunked_array->num_chunks() > 0) {
606 // DictionaryChunkArrayNeedUnification() returned false so we can safely assume
607 // the dictionary of the first chunk applies everywhere
608 const auto& dict_array =
609 checked_cast<const DictionaryArray&>(*chunked_array->chunk(0));
610 dictionary_ = dict_array.dictionary();
611 } else {
612 dictionary_ = CreateEmptyArray(dict_type.value_type());
613 }
614 }
615 }
616
617 SEXP Allocate(R_xlen_t n) const {
618 cpp11::writable::integers data(n);

Callers

nothing calls this directly

Calls 15

ValueOrStopFunction · 0.85
StopIfNotOkFunction · 0.85
stopFunction · 0.85
CreateEmptyArrayFunction · 0.85
resizeMethod · 0.80
index_typeMethod · 0.80
MakeFunction · 0.50
typeMethod · 0.45
value_typeMethod · 0.45
num_chunksMethod · 0.45
dictionaryMethod · 0.45

Tested by

no test coverage detected