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

Method query_to_plan

datafusion/sql/src/query.rs:39–103  ·  view source on GitHub ↗

Generate a logical plan from an SQL query/subquery

(
        &self,
        query: Query,
        outer_planner_context: &mut PlannerContext,
    )

Source from the content-addressed store, hash-verified

37impl<S: ContextProvider> SqlToRel<'_, S> {
38 /// Generate a logical plan from an SQL query/subquery
39 pub(crate) fn query_to_plan(
40 &self,
41 query: Query,
42 outer_planner_context: &mut PlannerContext,
43 ) -> Result<LogicalPlan> {
44 // Each query has its own planner context, including CTEs that are visible within that query.
45 // It also inherits the CTEs from the outer query by cloning the outer planner context.
46 let mut query_plan_context = outer_planner_context.clone();
47 let planner_context = &mut query_plan_context;
48
49 let Query {
50 with,
51 body,
52 order_by,
53 limit_clause,
54 fetch,
55 locks: _,
56 for_clause: _,
57 settings: _,
58 format_clause: _,
59 pipe_operators,
60 } = query;
61
62 if fetch.is_some() {
63 return not_impl_err!("FETCH clause is not supported yet");
64 }
65
66 if let Some(with) = with {
67 self.plan_with_clause(with, planner_context)?;
68 }
69
70 let set_expr = *body;
71 let plan = match set_expr {
72 SetExpr::Select(mut select) => {
73 let select_into = select.into.take();
74 let plan =
75 self.select_to_plan(*select, order_by.clone(), planner_context)?;
76 let plan = self.limit(plan, limit_clause.clone(), planner_context)?;
77 // Process the `SELECT INTO` after `LIMIT`.
78 self.select_into(plan, select_into)
79 }
80 other => {
81 // The functions called from `set_expr_to_plan()` need more than 128KB
82 // stack in debug builds as investigated in:
83 // https://github.com/apache/datafusion/pull/13310#discussion_r1836813902
84 let plan = {
85 // scope for dropping _guard
86 let _guard = StackGuard::new(256 * 1024);
87 self.set_expr_to_plan(other, planner_context)
88 }?;
89 let oby_exprs = to_order_by_exprs(order_by)?;
90 let order_by_rex = self.order_by_to_sort_expr(
91 oby_exprs,
92 plan.schema(),
93 planner_context,
94 true,
95 None,
96 )?;

Callers 12

non_recursive_cteMethod · 0.80
copy_to_planMethod · 0.80
insert_to_planMethod · 0.80
set_expr_to_planMethod · 0.80
pipe_operator_setMethod · 0.80
parse_exists_subqueryMethod · 0.80
parse_in_subqueryMethod · 0.80
parse_scalar_subqueryMethod · 0.80

Calls 13

newFunction · 0.85
to_order_by_exprsFunction · 0.85
plan_with_clauseMethod · 0.80
select_to_planMethod · 0.80
select_intoMethod · 0.80
set_expr_to_planMethod · 0.80
order_by_to_sort_exprMethod · 0.80
pipe_operatorsMethod · 0.80
cloneMethod · 0.45
takeMethod · 0.45
limitMethod · 0.45
schemaMethod · 0.45

Tested by

no test coverage detected