-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Is your feature request related to a problem or challenge?
Some engines, like DuckDB and Clickhouse, supports lambda functions, like:
SELECT list_filter(numbers, x -> x > 40) as greater_than_40s FROM relationThere's already support for the syntax in sqlparser-rs
From #12206 (comment) by @jayzhan211
Describe the solution you'd like
One of
- Add
Expr::Lambda{arg_names: Vec<String>, expr: Expr}variant - Change
ScalarFunction.args:
struct ScalarFunction {
args: Vec<ScalarFunctionArgument>
... omitted
}
enum ScalarFunctionArgument {
Expr(Expr),
Lambda{ arg_names: Vec<String>, body: Expr }
}Create a LambdaPhysicalExpr that holds the lambda physical expr and returns ScalarValue::Null in PhysicalExpr::evaluate or an error(similar to NoOp and UnkownColumn)
Add ScalarUDFImpl::lambdas_schema to return the types of the args of all lambda arguments it receives, so a input schema can be built and used to generated the LambdaPhysicalExpr
And then, one of:
- Make
ScalarFunctionArgsgeneric over the arg type, withColumnarValueas default, and add a newScalarUDFmethodinvoke_with_lambda_args/invoke_higher_order_with_argsthat receivesScalarFunctionArgs<ColumnarValueOrLambda>instead ofScalarFunctionArgs, and has a default implementation callinginvoke_with_args, returning an error if any arg is an lambda. The lambda arg is created if any childrenPhysicalExpris aLambdaPhysicalExpr
enum ColumnarValueOrLambda {
Value(ColumnarValue),
Lambda(&dyn PhysicalExpr)
}
struct ScalarFunctionArgs<T = ColumnarValue> {
args: Vec<T>,
... omitted
}- Add
physical_exprs: Vec<Arc<dyn PhysicalExpr>>toScalarFunctionArgs, so lambda expressions can be extracted from - Add
LambdaScalarUDFtrait (Duplication withScalarUDF, more work and more code to mantain, less flexible than 1, one more trait to document and to users to reason about) - Change
ScalarFunctionArgs.argstoVec<ColumnarValueOrLambda>instead ofVec<ColumnarValue>(A lot of breakage, including public) - Add
Lambdavariant toColumnarValue(Even more breakge than 2, and a lambda doesn't quite fit the concept of a columnar value)
Describe alternatives you've considered
No response
Additional context
No response
Omega359
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request