| 133 | }; |
| 134 | |
| 135 | Result<std::shared_ptr<Schema>> GetProjectedSchemaFromExpression( |
| 136 | const compute::Expression& projection, |
| 137 | const std::shared_ptr<Schema>& dataset_schema) { |
| 138 | // process resultant dataset_schema after projection |
| 139 | FieldVector project_fields; |
| 140 | std::set<std::string> field_names; |
| 141 | if (auto call = projection.call()) { |
| 142 | if (call->function_name != "make_struct") { |
| 143 | return Status::Invalid("Top level projection expression call must be make_struct"); |
| 144 | } |
| 145 | for (auto field_ref : compute::FieldsInExpression(projection)) { |
| 146 | if (field_ref.IsName()) { |
| 147 | field_names.emplace(*field_ref.name()); |
| 148 | } else if (field_ref.IsNested()) { |
| 149 | // We keep the top-level field name. |
| 150 | auto nested_field_refs = *field_ref.nested_refs(); |
| 151 | field_names.emplace(*nested_field_refs[0].name()); |
| 152 | } else { |
| 153 | return Status::Invalid( |
| 154 | "No projected schema was supplied and we could not infer the projected " |
| 155 | "schema from the projection expression."); |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | for (auto f : field_names) { |
| 160 | auto field = dataset_schema->GetFieldByName(f); |
| 161 | if (field) { |
| 162 | // if the field is not present in the schema we ignore it. |
| 163 | // the case is if kAugmentedFields are present in the expression |
| 164 | // and if they are not present in the provided schema, we ignore them. |
| 165 | project_fields.push_back(std::move(field)); |
| 166 | } |
| 167 | } |
| 168 | return schema(project_fields); |
| 169 | } |
| 170 | |
| 171 | // Scan options has a number of options that we can infer from the dataset |
| 172 | // schema if they are not specified. |
nothing calls this directly
no test coverage detected