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

Method parse_in_subquery

datafusion/sql/src/expr/subquery.rs:48–91  ·  view source on GitHub ↗
(
        &self,
        expr: SQLExpr,
        subquery: Query,
        negated: bool,
        input_schema: &DFSchema,
        planner_context: &mut PlannerContext,
    )

Source from the content-addressed store, hash-verified

46 }
47
48 pub(super) fn parse_in_subquery(
49 &self,
50 expr: SQLExpr,
51 subquery: Query,
52 negated: bool,
53 input_schema: &DFSchema,
54 planner_context: &mut PlannerContext,
55 ) -> Result<Expr> {
56 planner_context.append_outer_query_schema(Arc::new(input_schema.clone()));
57
58 let mut spans = Spans::new();
59 if let SetExpr::Select(select) = &subquery.body.as_ref() {
60 for item in &select.projection {
61 if let SelectItem::UnnamedExpr(SQLExpr::Identifier(ident)) = item
62 && let Some(span) = Span::try_from_sqlparser_span(ident.span)
63 {
64 spans.add_span(span);
65 }
66 }
67 }
68
69 let sub_plan = self.query_to_plan(subquery, planner_context)?;
70 let outer_ref_columns = sub_plan.all_out_ref_exprs();
71 planner_context.pop_outer_query_schema();
72
73 self.validate_single_column(
74 &sub_plan,
75 &spans,
76 "Too many columns! The subquery should only return one column",
77 "Select only one column in the subquery",
78 )?;
79
80 let expr_obj = self.sql_to_expr(expr, input_schema, planner_context)?;
81
82 Ok(Expr::InSubquery(InSubquery::new(
83 Box::new(expr_obj),
84 Subquery {
85 subquery: Arc::new(sub_plan),
86 outer_ref_columns,
87 spans,
88 },
89 negated,
90 )))
91 }
92
93 pub(super) fn parse_scalar_subquery(
94 &self,

Callers 1

Calls 11

newFunction · 0.85
InSubqueryClass · 0.85
add_spanMethod · 0.80
query_to_planMethod · 0.80
all_out_ref_exprsMethod · 0.80
cloneMethod · 0.45
as_refMethod · 0.45
sql_to_exprMethod · 0.45

Tested by

no test coverage detected