(
&self,
left_expr: SQLExpr,
subquery: Query,
compare_op: &BinaryOperator,
quantifier: SetQuantifier,
input_schema: &DFSchema,
planner_context:
| 161 | } |
| 162 | |
| 163 | pub(super) fn parse_set_comparison_subquery( |
| 164 | &self, |
| 165 | left_expr: SQLExpr, |
| 166 | subquery: Query, |
| 167 | compare_op: &BinaryOperator, |
| 168 | quantifier: SetQuantifier, |
| 169 | input_schema: &DFSchema, |
| 170 | planner_context: &mut PlannerContext, |
| 171 | ) -> Result<Expr> { |
| 172 | planner_context.append_outer_query_schema(Arc::new(input_schema.clone())); |
| 173 | |
| 174 | let mut spans = Spans::new(); |
| 175 | if let SetExpr::Select(select) = subquery.body.as_ref() { |
| 176 | for item in &select.projection { |
| 177 | if let SelectItem::ExprWithAlias { alias, .. } = item |
| 178 | && let Some(span) = Span::try_from_sqlparser_span(alias.span) |
| 179 | { |
| 180 | spans.add_span(span); |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | let sub_plan = self.query_to_plan(subquery, planner_context)?; |
| 186 | let outer_ref_columns = sub_plan.all_out_ref_exprs(); |
| 187 | planner_context.pop_outer_query_schema(); |
| 188 | |
| 189 | self.validate_single_column( |
| 190 | &sub_plan, |
| 191 | &spans, |
| 192 | "Too many columns! The subquery should only return one column", |
| 193 | "Select only one column in the subquery", |
| 194 | )?; |
| 195 | |
| 196 | let expr_obj = self.sql_to_expr(left_expr, input_schema, planner_context)?; |
| 197 | Ok(Expr::SetComparison(SetComparison::new( |
| 198 | Box::new(expr_obj), |
| 199 | Subquery { |
| 200 | subquery: Arc::new(sub_plan), |
| 201 | outer_ref_columns, |
| 202 | spans, |
| 203 | }, |
| 204 | self.parse_sql_binary_op(compare_op)?, |
| 205 | quantifier, |
| 206 | ))) |
| 207 | } |
| 208 | } |
no test coverage detected