FunctionFactory

Trait FunctionFactory 

Source
pub trait FunctionFactory:
    Debug
    + Sync
    + Send {
    // Required method
    fn create<'life0, 'life1, 'async_trait>(
        &'life0 self,
        state: &'life1 SessionState,
        statement: CreateFunction,
    ) -> Pin<Box<dyn Future<Output = Result<RegisterFunction>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Interface for handling CREATE FUNCTION statements and interacting with SessionState to create and register functions (ScalarUDF, AggregateUDF, WindowUDF, and TableFunctionImpl) dynamically.

Implement this trait to create user-defined functions in a custom way, such as loading from external libraries or defining them programmatically. DataFusion will parse CREATE FUNCTION statements into CreateFunction structs and pass them to the create method.

Note there is no default implementation of this trait provided in DataFusion, because the implementation and requirements vary widely. Please see function_factory example for a reference implementation.

§Examples of syntax that can be supported

CREATE FUNCTION f1(BIGINT)
  RETURNS BIGINT
  RETURN $1 + 1;

or

CREATE FUNCTION to_miles(DOUBLE)
RETURNS DOUBLE
LANGUAGE PYTHON
AS '
import pyarrow.compute as pc

conversation_rate_multiplier = 0.62137119

def to_miles(km_data):
    return pc.multiply(km_data, conversation_rate_multiplier)
'

Required Methods§

Source

fn create<'life0, 'life1, 'async_trait>( &'life0 self, state: &'life1 SessionState, statement: CreateFunction, ) -> Pin<Box<dyn Future<Output = Result<RegisterFunction>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Creates a new dynamic function from the SQL in the CreateFunction statement

Implementors§