| 185 | } |
| 186 | |
| 187 | Status ResolveOneFieldRef( |
| 188 | const SchemaManifest& manifest, const FieldRef& field_ref, |
| 189 | const std::unordered_map<std::string, const SchemaField*>& field_lookup, |
| 190 | const std::unordered_set<std::string>& duplicate_fields, |
| 191 | std::vector<int>* columns_selection) { |
| 192 | if (const std::string* name = field_ref.name()) { |
| 193 | auto it = field_lookup.find(*name); |
| 194 | if (it != field_lookup.end()) { |
| 195 | AddColumnIndices(*it->second, columns_selection); |
| 196 | } else if (duplicate_fields.find(*name) != duplicate_fields.end()) { |
| 197 | // We shouldn't generally get here because SetProjection will reject such references |
| 198 | return Status::Invalid("Ambiguous reference to column '", *name, |
| 199 | "' which occurs more than once"); |
| 200 | } |
| 201 | // "Virtual" column: field is not in file but is in the ScanOptions. |
| 202 | // Ignore it here, as projection will pad the batch with a null column. |
| 203 | return Status::OK(); |
| 204 | } |
| 205 | |
| 206 | const SchemaField* toplevel = nullptr; |
| 207 | const SchemaField* field = nullptr; |
| 208 | if (const std::vector<FieldRef>* refs = field_ref.nested_refs()) { |
| 209 | // Only supports a sequence of names |
| 210 | for (const auto& ref : *refs) { |
| 211 | if (const std::string* name = ref.name()) { |
| 212 | if (!field) { |
| 213 | // First lookup, top-level field |
| 214 | auto it = field_lookup.find(*name); |
| 215 | if (it != field_lookup.end()) { |
| 216 | field = it->second; |
| 217 | toplevel = field; |
| 218 | } else if (duplicate_fields.find(*name) != duplicate_fields.end()) { |
| 219 | return Status::Invalid("Ambiguous reference to column '", *name, |
| 220 | "' which occurs more than once"); |
| 221 | } else { |
| 222 | // Virtual column |
| 223 | return Status::OK(); |
| 224 | } |
| 225 | } else { |
| 226 | const SchemaField* result = nullptr; |
| 227 | for (const auto& child : field->children) { |
| 228 | if (child.field->name() == *name) { |
| 229 | if (!result) { |
| 230 | result = &child; |
| 231 | } else { |
| 232 | return Status::Invalid("Ambiguous nested reference to column '", *name, |
| 233 | "' which occurs more than once in field ", |
| 234 | field->field->ToString()); |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | if (!result) { |
| 239 | // Virtual column |
| 240 | return Status::OK(); |
| 241 | } |
| 242 | field = result; |
| 243 | } |
| 244 | continue; |
no test coverage detected