You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Construction of user-defined table functions (UDTFs) should be async to allow for async schemas #10889
Is your feature request related to a problem or challenge?
Accessing a TableProviders schema is a sync function call (see here). This means that the TableProvider must know its schema before construction.
DataFusion recently introduced TableFunctionImpl, which allows users to define a function to create a TableProvider. Unfortunately, this call method is sync, meaning that the user-defined table function must know its schema upfront in a non-blocking way. This isn't possible when implementing TableProviders, which might infer their schema async, like an HTTP connector that can connect to arbitrary sources with payloads only known once the response is streaming in.
Describe the solution you'd like
I propose we make the call method async to allow for async schemas and thus async table provider construction.
current code
usesuper::TableProvider;use datafusion_common::Result;use datafusion_expr::Expr;use std::sync::Arc;/// A trait for table function implementationspubtraitTableFunctionImpl:Sync + Send{/// Create a table providerfncall(&self,args:&[Expr]) -> Result<Arc<dynTableProvider>>;}/// A table that uses a function to generate datapubstructTableFunction{/// Name of the table functionname:String,/// Function implementationfun:Arc<dynTableFunctionImpl>,}implTableFunction{/// Create a new table functionpubfnnew(name:String,fun:Arc<dynTableFunctionImpl>) -> Self{Self{ name, fun }}/// Get the name of the table functionpubfnname(&self) -> &str{&self.name}/// Get the function implementation and generate a tablepubfncreate_table_provider(&self,args:&[Expr]) -> Result<Arc<dynTableProvider>>{self.fun.call(args)}}
where the new trait would looks something like
/// A trait for table function implementationspubtraitTableFunctionImpl:Sync + Send{/// Create a table providerasyncfncall(&self,args:&[Expr]) -> Result<Arc<dynTableProvider>>;}
Describe alternatives you've considered
I've worked around this by creating the table outside of data fusion, but I would prefer to use the table functions to achieve the same thing.
Additional context
No response
Reacted by Dima Pristupa, Sergii Mikhtoniuk and gstvg
Activity
alamb commentedon Jun 14, 2024
I think this proposal sounds like a great idea to me, FWIW
Thank you for the suggestion @matthewgapp