File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
datafusion/sql/src/relation Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -400,6 +400,48 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
400400
401401 ( unpivot_plan, alias)
402402 }
403+ TableFactor :: Function {
404+ name, args, alias, ..
405+ } => {
406+ let tbl_func_ref = self . object_name_to_table_reference ( name) ?;
407+ let schema = planner_context
408+ . outer_query_schema ( )
409+ . cloned ( )
410+ . unwrap_or_else ( DFSchema :: empty) ;
411+ let func_args = args
412+ . into_iter ( )
413+ . map ( |arg| match arg {
414+ FunctionArg :: Unnamed ( FunctionArgExpr :: Expr ( expr) ) => {
415+ let expr = self . sql_expr_to_logical_expr (
416+ expr,
417+ & schema,
418+ planner_context,
419+ ) ?;
420+ Ok ( ( expr, None ) )
421+ }
422+ FunctionArg :: Named {
423+ name,
424+ arg : FunctionArgExpr :: Expr ( expr) ,
425+ ..
426+ } => {
427+ let expr = self . sql_expr_to_logical_expr (
428+ expr,
429+ & schema,
430+ planner_context,
431+ ) ?;
432+ Ok ( ( expr, Some ( name. value . clone ( ) ) ) )
433+ }
434+ _ => plan_err ! ( "Unsupported function argument: {arg:?}" ) ,
435+ } )
436+ . collect :: < Result < Vec < ( Expr , Option < String > ) > > > ( ) ?;
437+ let tbl_func_name = tbl_func_ref. table ( ) . to_ascii_lowercase ( ) ;
438+ let provider = self
439+ . context_provider
440+ . get_table_function_source ( & tbl_func_name, func_args) ?;
441+ let plan =
442+ LogicalPlanBuilder :: scan ( tbl_func_name, provider, None ) ?. build ( ) ?;
443+ ( plan, alias)
444+ }
403445 // @todo: Support TableFactory::TableFunction
404446 _ => {
405447 return not_impl_err ! (
You can’t perform that action at this time.
0 commit comments