MCPcopy Create free account
hub / github.com/apache/datafusion / validate_schema_satisfies_exprs

Method validate_schema_satisfies_exprs

datafusion/sql/src/planner.rs:585–646  ·  view source on GitHub ↗

Validate the schema provides all of the columns referenced in the expressions.

(
        &self,
        schema: &DFSchema,
        exprs: &[Expr],
    )

Source from the content-addressed store, hash-verified

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,

Callers 4

select_to_planMethod · 0.80
projectMethod · 0.80
sql_to_exprMethod · 0.80

Calls 14

find_column_exprsFunction · 0.85
field_not_foundFunction · 0.85
with_diagnosticMethod · 0.80
iterMethod · 0.45
mapMethod · 0.45
is_emptyMethod · 0.45
cloneMethod · 0.45
as_strMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected