If we are selecting only certain fields, populate an inclusion mask for fast lookups. Additionally, drop deselected fields from the reader's schema.
| 822 | // If we are selecting only certain fields, populate an inclusion mask for fast lookups. |
| 823 | // Additionally, drop deselected fields from the reader's schema. |
| 824 | Status GetInclusionMaskAndOutSchema(const std::shared_ptr<Schema>& full_schema, |
| 825 | const std::vector<int>& included_indices, |
| 826 | std::vector<bool>* inclusion_mask, |
| 827 | std::shared_ptr<Schema>* out_schema) { |
| 828 | inclusion_mask->clear(); |
| 829 | if (included_indices.empty()) { |
| 830 | *out_schema = full_schema; |
| 831 | return Status::OK(); |
| 832 | } |
| 833 | |
| 834 | inclusion_mask->resize(full_schema->num_fields(), false); |
| 835 | |
| 836 | auto included_indices_sorted = included_indices; |
| 837 | std::sort(included_indices_sorted.begin(), included_indices_sorted.end()); |
| 838 | |
| 839 | FieldVector included_fields; |
| 840 | for (int i : included_indices_sorted) { |
| 841 | // Ignore out of bounds indices |
| 842 | if (i < 0 || i >= full_schema->num_fields()) { |
| 843 | return Status::Invalid("Out of bounds field index: ", i); |
| 844 | } |
| 845 | |
| 846 | if (inclusion_mask->at(i)) continue; |
| 847 | |
| 848 | inclusion_mask->at(i) = true; |
| 849 | included_fields.push_back(full_schema->field(i)); |
| 850 | } |
| 851 | |
| 852 | *out_schema = schema(std::move(included_fields), full_schema->endianness(), |
| 853 | full_schema->metadata()); |
| 854 | return Status::OK(); |
| 855 | } |
| 856 | |
| 857 | Status UnpackSchemaMessage(const void* opaque_schema, const IpcReadOptions& options, |
| 858 | DictionaryMemo* dictionary_memo, |
no test coverage detected