(
&self,
subquery: Query,
input_schema: &DFSchema,
planner_context: &mut PlannerContext,
)
| 91 | } |
| 92 | |
| 93 | pub(super) fn parse_scalar_subquery( |
| 94 | &self, |
| 95 | subquery: Query, |
| 96 | input_schema: &DFSchema, |
| 97 | planner_context: &mut PlannerContext, |
| 98 | ) -> Result<Expr> { |
| 99 | planner_context.append_outer_query_schema(Arc::new(input_schema.clone())); |
| 100 | let mut spans = Spans::new(); |
| 101 | if let SetExpr::Select(select) = subquery.body.as_ref() { |
| 102 | for item in &select.projection { |
| 103 | if let SelectItem::ExprWithAlias { alias, .. } = item |
| 104 | && let Some(span) = Span::try_from_sqlparser_span(alias.span) |
| 105 | { |
| 106 | spans.add_span(span); |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | let sub_plan = self.query_to_plan(subquery, planner_context)?; |
| 111 | let outer_ref_columns = sub_plan.all_out_ref_exprs(); |
| 112 | planner_context.pop_outer_query_schema(); |
| 113 | |
| 114 | self.validate_single_column( |
| 115 | &sub_plan, |
| 116 | &spans, |
| 117 | "Too many columns! The subquery should only return one column", |
| 118 | "Select only one column in the subquery", |
| 119 | )?; |
| 120 | |
| 121 | Ok(Expr::ScalarSubquery(Subquery { |
| 122 | subquery: Arc::new(sub_plan), |
| 123 | outer_ref_columns, |
| 124 | spans, |
| 125 | })) |
| 126 | } |
| 127 | |
| 128 | fn validate_single_column( |
| 129 | &self, |
no test coverage detected