Validate the schema provides all of the columns referenced in the expressions.
(
&self,
schema: &DFSchema,
exprs: &[Expr],
)
| 583 | |
| 584 | /// Validate the schema provides all of the columns referenced in the expressions. |
| 585 | pub(crate) fn validate_schema_satisfies_exprs( |
| 586 | &self, |
| 587 | schema: &DFSchema, |
| 588 | exprs: &[Expr], |
| 589 | ) -> Result<()> { |
| 590 | find_column_exprs(exprs) |
| 591 | .iter() |
| 592 | .try_for_each(|col| match col { |
| 593 | Expr::Column(col) => match &col.relation { |
| 594 | Some(r) => schema.field_with_qualified_name(r, &col.name).map(|_| ()), |
| 595 | None => { |
| 596 | if !schema.fields_with_unqualified_name(&col.name).is_empty() { |
| 597 | Ok(()) |
| 598 | } else { |
| 599 | Err(field_not_found( |
| 600 | col.relation.clone(), |
| 601 | col.name.as_str(), |
| 602 | schema, |
| 603 | )) |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | .map_err(|err: DataFusionError| match &err { |
| 608 | DataFusionError::SchemaError(inner, _) |
| 609 | if matches!( |
| 610 | inner.as_ref(), |
| 611 | SchemaError::FieldNotFound { .. } |
| 612 | ) => |
| 613 | { |
| 614 | let SchemaError::FieldNotFound { |
| 615 | field, |
| 616 | valid_fields, |
| 617 | } = inner.as_ref() |
| 618 | else { |
| 619 | unreachable!() |
| 620 | }; |
| 621 | let mut diagnostic = if let Some(relation) = &col.relation { |
| 622 | Diagnostic::new_error( |
| 623 | format!( |
| 624 | "column '{}' not found in '{}'", |
| 625 | &col.name, relation |
| 626 | ), |
| 627 | col.spans().first(), |
| 628 | ) |
| 629 | } else { |
| 630 | Diagnostic::new_error( |
| 631 | format!("column '{}' not found", &col.name), |
| 632 | col.spans().first(), |
| 633 | ) |
| 634 | }; |
| 635 | add_possible_columns_to_diag( |
| 636 | &mut diagnostic, |
| 637 | field, |
| 638 | valid_fields, |
| 639 | ); |
| 640 | err.with_diagnostic(diagnostic) |
| 641 | } |
| 642 | _ => err, |
no test coverage detected