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

Method MakeStatisticsArray

cpp/src/arrow/record_batch.cc:643–777  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

641} // namespace
642
643Result<std::shared_ptr<Array>> RecordBatch::MakeStatisticsArray(
644 MemoryPool* memory_pool) const {
645 // Statistics schema:
646 // struct<
647 // column: int32,
648 // statistics: map<
649 // key: dictionary<
650 // indices: int32,
651 // dictionary: utf8,
652 // >,
653 // items: dense_union<...all needed types...>,
654 // >
655 // >
656
657 // Statistics schema doesn't define static dense union type for
658 // values. Each statistics schema have a dense union type that has
659 // needled value types. The following block collects these types.
660 std::vector<std::shared_ptr<Field>> values_types;
661 std::vector<int8_t> values_type_indexes;
662 RETURN_NOT_OK(EnumerateStatistics(*this, [&](const EnumeratedStatistics& statistics) {
663 int8_t i = 0;
664 for (const auto& field : values_types) {
665 if (field->type()->Equals(statistics.type)) {
666 break;
667 }
668 i++;
669 }
670 if (i == static_cast<int8_t>(values_types.size())) {
671 values_types.push_back(field(statistics.type->name(), statistics.type));
672 }
673 values_type_indexes.push_back(i);
674 return Status::OK();
675 }));
676
677 // statistics.key: dictionary<indices: int32, dictionary: utf8>
678 auto keys_type = dictionary(int32(), utf8(), false);
679 // statistics.items: dense_union<...all needed types...>
680 auto values_type = dense_union(values_types);
681 // struct<
682 // column: int32,
683 // statistics: map<
684 // key: dictionary<
685 // indices: int32,
686 // dictionary: utf8,
687 // >,
688 // items: dense_union<...all needed types...>,
689 // >
690 // >
691 auto statistics_type =
692 struct_({field("column", int32()),
693 field("statistics", map(keys_type, values_type, false))});
694
695 std::vector<std::shared_ptr<ArrayBuilder>> field_builders;
696 // columns: int32
697 auto columns_builder = std::make_shared<Int32Builder>(memory_pool);
698 field_builders.push_back(std::static_pointer_cast<ArrayBuilder>(columns_builder));
699 // statistics.key: dictionary<indices: int32, dictionary: utf8>
700 auto keys_builder = std::make_shared<StringDictionary32Builder>();

Callers

nothing calls this directly

Calls 15

EnumerateStatisticsFunction · 0.85
dense_unionFunction · 0.85
struct_Function · 0.85
mapFunction · 0.85
push_backMethod · 0.80
fieldFunction · 0.70
OKFunction · 0.70
dictionaryFunction · 0.70
MakeBuilderFunction · 0.70
EqualsMethod · 0.45
typeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected