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