(
&self,
selection: Option<SQLExpr>,
plan: LogicalPlan,
planner_context: &mut PlannerContext,
)
| 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, |
no test coverage detected