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

Method create_default_relation

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

Source from the content-addressed store, hash-verified

143 }
144
145 fn create_default_relation(
146 &self,
147 relation: TableFactor,
148 planner_context: &mut PlannerContext,
149 ) -> Result<PlannedRelation> {
150 let relation_span = relation.span();
151 let (plan, alias) = match relation {
152 TableFactor::Table {
153 name, alias, args, ..
154 } => {
155 if let Some(func_args) = args {
156 let tbl_func_name =
157 name.0.first().unwrap().as_ident().unwrap().to_string();
158 let args = func_args
159 .args
160 .into_iter()
161 .map(|arg| {
162 if let FunctionArg::Unnamed(FunctionArgExpr::Expr(expr)) = arg
163 {
164 self.sql_expr_to_logical_expr(
165 expr,
166 &DFSchema::empty(),
167 planner_context,
168 )
169 } else {
170 plan_err!("Unsupported function argument type: {}", arg)
171 }
172 })
173 .collect::<Result<Vec<_>>>()?;
174 let provider = self
175 .context_provider
176 .get_table_function_source(&tbl_func_name, args)?;
177 let plan = LogicalPlanBuilder::scan(
178 TableReference::Bare {
179 table: format!("{tbl_func_name}()").into(),
180 },
181 provider,
182 None,
183 )?
184 .build()?;
185 (plan, alias)
186 } else {
187 // Normalize name and alias
188 let table_ref = self.object_name_to_table_reference(name)?;
189 let table_name = table_ref.to_string();
190 let cte = planner_context.get_cte(&table_name);
191 (
192 match (
193 cte,
194 self.context_provider.get_table_source(table_ref.clone()),
195 ) {
196 (Some(cte_plan), _) => Ok(cte_plan.clone()),
197 (_, Ok(provider)) => LogicalPlanBuilder::scan(
198 table_ref.clone(),
199 provider,
200 None,
201 )?
202 .build(),

Callers 1

create_relationMethod · 0.80

Calls 15

newFunction · 0.85
spanMethod · 0.80
as_identMethod · 0.80
get_cteMethod · 0.80
with_diagnosticMethod · 0.80
query_to_planMethod · 0.80
plan_table_with_joinsMethod · 0.80
try_process_unnestMethod · 0.80
lastMethod · 0.80
outer_queries_schemasMethod · 0.80
emptyFunction · 0.50
scanFunction · 0.50

Tested by

no test coverage detected