Scan options has a number of options that we can infer from the dataset schema if they are not specified.
| 171 | // Scan options has a number of options that we can infer from the dataset |
| 172 | // schema if they are not specified. |
| 173 | Status NormalizeScanOptions(const std::shared_ptr<ScanOptions>& scan_options, |
| 174 | const std::shared_ptr<Schema>& dataset_schema) { |
| 175 | if (scan_options->dataset_schema == nullptr) { |
| 176 | scan_options->dataset_schema = dataset_schema; |
| 177 | } |
| 178 | |
| 179 | if (!scan_options->filter.IsBound()) { |
| 180 | ARROW_ASSIGN_OR_RAISE(scan_options->filter, |
| 181 | scan_options->filter.Bind(*dataset_schema)); |
| 182 | } |
| 183 | |
| 184 | if (!scan_options->projected_schema) { |
| 185 | // If the user specifies a projection expression we can maybe infer from |
| 186 | // that expression |
| 187 | if (scan_options->projection.IsBound()) { |
| 188 | ARROW_ASSIGN_OR_RAISE( |
| 189 | auto project_schema, |
| 190 | GetProjectedSchemaFromExpression(scan_options->projection, dataset_schema)); |
| 191 | if (project_schema->num_fields() > 0) { |
| 192 | scan_options->projected_schema = std::move(project_schema); |
| 193 | } |
| 194 | // If the projection isn't a call we assume it's literal(true) or some |
| 195 | // invalid expression and just ignore it. It will be replaced below |
| 196 | } |
| 197 | |
| 198 | // If we couldn't infer it from the projection expression then just grab all |
| 199 | // fields from the dataset |
| 200 | if (!scan_options->projected_schema) { |
| 201 | // Until now, we assume the project expression is bound, but if it is not |
| 202 | // bound, we have to check the expressions and make sure bind them |
| 203 | // and create the projected schema based on the field_refs (which guarantees |
| 204 | // IsName() to be true). |
| 205 | |
| 206 | // process resultant dataset_schema after projection |
| 207 | ARROW_ASSIGN_OR_RAISE( |
| 208 | auto projected_schema, |
| 209 | GetProjectedSchemaFromExpression(scan_options->projection, dataset_schema)); |
| 210 | |
| 211 | if (projected_schema->num_fields() > 0) { |
| 212 | // create the projected schema only if the provided expressions |
| 213 | // produces valid set of fields. |
| 214 | ARROW_ASSIGN_OR_RAISE(auto projection_descr, |
| 215 | ProjectionDescr::Default( |
| 216 | *projected_schema, scan_options->add_augmented_fields)); |
| 217 | scan_options->projected_schema = std::move(projection_descr.schema); |
| 218 | scan_options->projection = projection_descr.expression; |
| 219 | ARROW_ASSIGN_OR_RAISE(scan_options->projection, |
| 220 | scan_options->projection.Bind(*projected_schema)); |
| 221 | } else { |
| 222 | // if projected_fields are not found, we default to creating the projected_schema |
| 223 | // and projection from the dataset_schema. |
| 224 | ARROW_ASSIGN_OR_RAISE(auto projection_descr, |
| 225 | ProjectionDescr::Default( |
| 226 | *dataset_schema, scan_options->add_augmented_fields)); |
| 227 | scan_options->projected_schema = std::move(projection_descr.schema); |
| 228 | scan_options->projection = projection_descr.expression; |
| 229 | } |
| 230 | } |
no test coverage detected