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