If we are selecting only certain fields, populate an inclusion mask for fast lookups. Additionally, drop deselected fields from the reader's schema.
| 837 | // If we are selecting only certain fields, populate an inclusion mask for fast lookups. |
| 838 | // Additionally, drop deselected fields from the reader's schema. |
| 839 | Status GetInclusionMaskAndOutSchema(const std::shared_ptr<Schema>& full_schema, |
| 840 | const std::vector<int>& included_indices, |
| 841 | std::vector<bool>* inclusion_mask, |
| 842 | std::shared_ptr<Schema>* out_schema) { |
| 843 | inclusion_mask->clear(); |
| 844 | if (included_indices.empty()) { |
| 845 | *out_schema = full_schema; |
| 846 | return Status::OK(); |
| 847 | } |
| 848 | |
| 849 | inclusion_mask->resize(full_schema->num_fields(), false); |
| 850 | |
| 851 | auto included_indices_sorted = included_indices; |
| 852 | std::sort(included_indices_sorted.begin(), included_indices_sorted.end()); |
| 853 | |
| 854 | FieldVector included_fields; |
| 855 | for (int i : included_indices_sorted) { |
| 856 | // Ignore out of bounds indices |
| 857 | if (i < 0 || i >= full_schema->num_fields()) { |
| 858 | return Status::Invalid("Out of bounds field index: ", i); |
| 859 | } |
| 860 | |
| 861 | if (inclusion_mask->at(i)) continue; |
| 862 | |
| 863 | inclusion_mask->at(i) = true; |
| 864 | included_fields.push_back(full_schema->field(i)); |
| 865 | } |
| 866 | |
| 867 | *out_schema = schema(std::move(included_fields), full_schema->endianness(), |
| 868 | full_schema->metadata()); |
| 869 | return Status::OK(); |
| 870 | } |
| 871 | |
| 872 | Status UnpackSchemaMessage(const void* opaque_schema, const IpcReadOptions& options, |
| 873 | DictionaryMemo* dictionary_memo, |
no test coverage detected