| 843 | } |
| 844 | |
| 845 | Result<ProjectionDescr> ProjectionDescr::FromNames(std::vector<std::string> names, |
| 846 | const Schema& dataset_schema, |
| 847 | bool add_augmented_fields) { |
| 848 | std::vector<compute::Expression> exprs(names.size()); |
| 849 | for (size_t i = 0; i < exprs.size(); ++i) { |
| 850 | // If name isn't in schema, try finding it by dotted path. |
| 851 | if (dataset_schema.GetFieldByName(names[i]) == nullptr) { |
| 852 | auto name = names[i]; |
| 853 | if (name.rfind(".", 0) != 0) { |
| 854 | name = "." + name; |
| 855 | } |
| 856 | ARROW_ASSIGN_OR_RAISE(auto field_ref, FieldRef::FromDotPath(name)); |
| 857 | // safe as we know there is at least 1 dot. |
| 858 | names[i] = name.substr(name.rfind(".") + 1); |
| 859 | exprs[i] = compute::field_ref(field_ref); |
| 860 | } else { |
| 861 | exprs[i] = compute::field_ref(names[i]); |
| 862 | } |
| 863 | } |
| 864 | auto fields = dataset_schema.fields(); |
| 865 | if (add_augmented_fields) { |
| 866 | for (const auto& aug_field : kAugmentedFields) { |
| 867 | fields.push_back(aug_field); |
| 868 | } |
| 869 | } |
| 870 | return ProjectionDescr::FromExpressions(std::move(exprs), std::move(names), |
| 871 | Schema(fields, dataset_schema.metadata())); |
| 872 | } |
| 873 | |
| 874 | Result<ProjectionDescr> ProjectionDescr::Default(const Schema& dataset_schema, |
| 875 | bool add_augmented_fields) { |