use super::TableProvider;
use datafusion_common::Result;
use datafusion_expr::Expr;
use std::sync::Arc;
pub trait TableFunctionImpl: Sync + Send {
fn call(&self, args: &[Expr]) -> Result<Arc<dyn TableProvider>>;
}
pub struct TableFunction {
name: String,
fun: Arc<dyn TableFunctionImpl>,
}
impl TableFunction {
pub fn new(name: String, fun: Arc<dyn TableFunctionImpl>) -> Self {
Self { name, fun }
}
pub fn name(&self) -> &str {
&self.name
}
pub fn function(&self) -> &Arc<dyn TableFunctionImpl> {
&self.fun
}
pub fn create_table_provider(&self, args: &[Expr]) -> Result<Arc<dyn TableProvider>> {
self.fun.call(args)
}
}