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

Method plan_selection

datafusion/sql/src/select.rs:701–748  ·  view source on GitHub ↗
(
        &self,
        selection: Option<SQLExpr>,
        plan: LogicalPlan,
        planner_context: &mut PlannerContext,
    )

Source from the content-addressed store, hash-verified

699 }
700
701 pub(crate) fn plan_selection(
702 &self,
703 selection: Option<SQLExpr>,
704 plan: LogicalPlan,
705 planner_context: &mut PlannerContext,
706 ) -> Result<LogicalPlan> {
707 match selection {
708 Some(predicate_expr) => {
709 let fallback_schemas = plan.fallback_normalize_schemas();
710
711 let filter_expr =
712 self.sql_to_expr(predicate_expr, plan.schema(), planner_context)?;
713
714 // Check for aggregation functions
715 let aggregate_exprs =
716 find_aggregate_exprs(std::slice::from_ref(&filter_expr));
717 if !aggregate_exprs.is_empty() {
718 return plan_err!(
719 "Aggregate functions are not allowed in the WHERE clause. Consider using HAVING instead"
720 );
721 }
722
723 let mut using_columns = HashSet::new();
724 expr_to_columns(&filter_expr, &mut using_columns)?;
725 let mut schema_stack: Vec<Vec<&DFSchema>> =
726 vec![vec![plan.schema()], fallback_schemas];
727 for sc in planner_context.outer_schemas_iter() {
728 schema_stack.push(vec![sc.as_ref()]);
729 }
730
731 let filter_expr = normalize_col_with_schemas_and_ambiguity_check(
732 filter_expr,
733 schema_stack
734 .iter()
735 .map(|sc| sc.as_slice())
736 .collect::<Vec<&[&DFSchema]>>()
737 .as_slice(),
738 &[using_columns],
739 )?;
740
741 Ok(LogicalPlan::Filter(Filter::try_new(
742 filter_expr,
743 Arc::new(plan),
744 )?))
745 }
746 None => Ok(plan),
747 }
748 }
749
750 pub(crate) fn plan_from_tables(
751 &self,

Callers 2

select_to_planMethod · 0.80
pipe_operatorMethod · 0.80

Calls 13

find_aggregate_exprsFunction · 0.85
newFunction · 0.85
expr_to_columnsFunction · 0.85
outer_schemas_iterMethod · 0.80
FilterClass · 0.50
sql_to_exprMethod · 0.45
schemaMethod · 0.45
is_emptyMethod · 0.45
pushMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected