| 828 | } |
| 829 | |
| 830 | void SchemaDescriptor::BuildTree(const NodePtr& node, int16_t max_def_level, |
| 831 | int16_t max_rep_level, const NodePtr& base) { |
| 832 | if (node->is_optional()) { |
| 833 | ++max_def_level; |
| 834 | } else if (node->is_repeated()) { |
| 835 | // Repeated fields add a definition level. This is used to distinguish |
| 836 | // between an empty list and a list with an item in it. |
| 837 | ++max_rep_level; |
| 838 | ++max_def_level; |
| 839 | } |
| 840 | |
| 841 | // Now, walk the schema and create a ColumnDescriptor for each leaf node |
| 842 | if (node->is_group()) { |
| 843 | const GroupNode* group = static_cast<const GroupNode*>(node.get()); |
| 844 | for (int i = 0; i < group->field_count(); ++i) { |
| 845 | BuildTree(group->field(i), max_def_level, max_rep_level, base); |
| 846 | } |
| 847 | } else { |
| 848 | node_to_leaf_index_[static_cast<const PrimitiveNode*>(node.get())] = |
| 849 | static_cast<int>(leaves_.size()); |
| 850 | |
| 851 | // Primitive node, append to leaves |
| 852 | leaves_.push_back(ColumnDescriptor(node, max_def_level, max_rep_level, this)); |
| 853 | leaf_to_base_.emplace(static_cast<int>(leaves_.size()) - 1, base); |
| 854 | leaf_to_idx_.emplace(node->path()->ToDotString(), |
| 855 | static_cast<int>(leaves_.size()) - 1); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | int SchemaDescriptor::GetColumnIndex(const PrimitiveNode& node) const { |
| 860 | auto it = node_to_leaf_index_.find(&node); |
nothing calls this directly
no test coverage detected