-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Lambda functions to parser #1313
Conversation
CC @mbasmanova |
Mark, this is great. To confirm, does this PR include support for multiple arguments for lambda, e.g. |
It supports only single argument captures right now, e.g. |
As for captures, the parser will not do anything besides transforming the expression. It is up to the binder to actually resolve columns. i.e.
The binder is then in charge of resolving "x" back to the lambda, and "int_column" to another data source (e.g. a table). |
+optional type specification for lambda |
Mark, thanks for explaining. To clarify the terminology, lambda in |
That makes a lot of sense; will do. Thanks for the feedback! |
…as such as x -> x > 10 AND z < 20 are correctly parsed
All the changes are implemented now, lambda functions now look like this: class LambdaExpression : public ParsedExpression {
vector<string> parameters;
unique_ptr<ParsedExpression> expression;
}; I also fixed several operator precedence rules so that lambda arrows take priority over other operators, which causes e.g. select map(i, (x, y) -> x + y) from tbl;
-- lambda: parameters { x, y }, function: x + y
select map(i, x -> x + 1) from (values (list_value(1, 2, 3))) tbl(i);
-- lambda: parameters { x }, function: x + 1
select map(i, x -> x + 1 AND y + 1) from (values (list_value(1, 2, 3))) tbl(i);
-- lambda: parameters { x }, function: x -> x + 1 AND y + 1 |
Nice. Thank you, Mark. |
…end_parser_scan.cpp to avoid triggering R CRAN warnings
This PR adds basic support for lambda functions to the parser. They are not supported anywhere else yet and not bound yet, but the plan is to use them later on in functions that can apply to lists.
Lambda expressions look like this:
Example syntax: