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

Method create_relation_subquery

datafusion/sql/src/relation/mod.rs:307–364  ·  view source on GitHub ↗
(
        &self,
        subquery: TableFactor,
        planner_context: &mut PlannerContext,
    )

Source from the content-addressed store, hash-verified

305 }
306
307 pub(crate) fn create_relation_subquery(
308 &self,
309 subquery: TableFactor,
310 planner_context: &mut PlannerContext,
311 ) -> Result<LogicalPlan> {
312 // At this point for a syntactically valid query the outer_from_schema is
313 // guaranteed to be set, so the `.unwrap()` call will never panic. This
314 // is the case because we only call this method for lateral table
315 // factors, and those can never be the first factor in a FROM list. This
316 // means we arrived here through the `for` loop in `plan_from_tables` or
317 // the `for` loop in `plan_table_with_joins`.
318 let old_from_schema = planner_context
319 .set_outer_from_schema(None)
320 .unwrap_or_else(|| Arc::new(DFSchema::empty()));
321 let outer_query_schema = planner_context.pop_outer_query_schema();
322 let new_query_schema = match outer_query_schema {
323 Some(ref old_query_schema) => {
324 let mut new_query_schema = old_from_schema.as_ref().clone();
325 new_query_schema.merge(old_query_schema.as_ref());
326 Arc::new(new_query_schema)
327 }
328 None => Arc::clone(&old_from_schema),
329 };
330 planner_context.append_outer_query_schema(new_query_schema);
331
332 let plan = self.create_relation(subquery, planner_context)?;
333 let outer_ref_columns = plan.all_out_ref_exprs();
334
335 planner_context.pop_outer_query_schema();
336 if let Some(schema) = outer_query_schema {
337 planner_context.append_outer_query_schema(schema);
338 }
339 planner_context.set_outer_from_schema(Some(old_from_schema));
340
341 // We can omit the subquery wrapper if there are no columns
342 // referencing the outer scope.
343 if outer_ref_columns.is_empty() {
344 return Ok(plan);
345 }
346
347 match plan {
348 LogicalPlan::SubqueryAlias(SubqueryAlias { input, alias, .. }) => {
349 subquery_alias(
350 LogicalPlan::Subquery(Subquery {
351 subquery: input,
352 outer_ref_columns,
353 spans: Spans::new(),
354 }),
355 alias,
356 )
357 }
358 plan => Ok(LogicalPlan::Subquery(Subquery {
359 subquery: Arc::new(plan),
360 outer_ref_columns,
361 spans: Spans::new(),
362 })),
363 }
364 }

Callers 2

plan_table_with_joinsMethod · 0.80
parse_relation_joinMethod · 0.80

Calls 13

newFunction · 0.85
subquery_aliasFunction · 0.85
SubqueryClass · 0.85
set_outer_from_schemaMethod · 0.80
create_relationMethod · 0.80
all_out_ref_exprsMethod · 0.80
emptyFunction · 0.50
cloneMethod · 0.45
as_refMethod · 0.45
mergeMethod · 0.45

Tested by

no test coverage detected