| 558 | } |
| 559 | |
| 560 | pub(crate) fn apply_expr_alias( |
| 561 | &self, |
| 562 | plan: LogicalPlan, |
| 563 | idents: Vec<Ident>, |
| 564 | ) -> Result<LogicalPlan> { |
| 565 | if idents.is_empty() { |
| 566 | Ok(plan) |
| 567 | } else if idents.len() != plan.schema().fields().len() { |
| 568 | plan_err!( |
| 569 | "Source table contains {} columns but only {} \ |
| 570 | names given as column alias", |
| 571 | plan.schema().fields().len(), |
| 572 | idents.len() |
| 573 | ) |
| 574 | } else { |
| 575 | let fields = plan.schema().fields().clone(); |
| 576 | LogicalPlanBuilder::from(plan) |
| 577 | .project(fields.iter().zip(idents).map(|(field, ident)| { |
| 578 | col(field.name()).alias(self.ident_normalizer.normalize(ident)) |
| 579 | }))? |
| 580 | .build() |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | /// Validate the schema provides all of the columns referenced in the expressions. |
| 585 | pub(crate) fn validate_schema_satisfies_exprs( |