Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] Adds SQL function modules (#2725)
This commit defines _SQLFunctions_ and _SQLModule_ which are responsible for registering the Daft _FunctionExpr_ to be accessible from SQL statements. It is basic and operates on-top-of _FunctionExpr_ .. that is, without modifying it. * SQLFunctions – map of names (String) to functions (SQLFunction) * SQLFunction – wrapper type over _FunctionExpr_ to get the _validate_ method. * SQLModule – holds necessary logic for a _FunctionExpr_ variant i.e. NumericExpr, Utf8Expr, etc. ### Overview ```rust /// SQLModule for FunctionExpr::Numeric impl SQLModule for SQLModuleNumeric { fn register(parent: &mut SQLFunctions) { use FunctionExpr::Numeric as f; use NumericExpr::*; parent.add("abs", f(Abs)); .... } } // register let mut functions = SQLFunctions::new(); functions.register::<SQLModuleNumeric>(); // usage let args = plan_args(args) let func = functions.get("abs") let expr = func.validate(args)? ``` ### Future Considerations * Remove SQLFunctions global lazy-static singleton; rather, make it owned by (field of) the planner. * Remove SQLFunction wrapper type in favor of extending FunctionEvaluator trait * Add arity checks once there are variants. * Use multi-map to support function variants. * Extract input validation duplication from _to_field_ and _evaluate_ to be used by SQLPlanner as well. * Derive a module from macros on the daft_dsl declarations
- Loading branch information