-
Notifications
You must be signed in to change notification settings - Fork 693
Snowflake: Lambda functions #2192
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
base: main
Are you sure you want to change the base?
Conversation
src/parser/mod.rs
Outdated
| Keyword::FILTER | ||
| | Keyword::TRANSFORM | ||
| | Keyword::REDUCE if self.dialect.supports_lambda_functions() => { | ||
| self.expect_token(&Token::LParen)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we move the logic to a standalone function? since its a lot of code to inline
| /// The name of the parameter | ||
| pub name: Ident, | ||
| /// The optional data type of the parameter | ||
| pub data_type: Option<DataType>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a link to the docs containing the data_type syntax?
tests/sqlparser_snowflake.rs
Outdated
| snowflake().verified_expr("TRANSFORM([1, 2, 3], a -> a * 2)"); | ||
| snowflake().verified_expr("TRANSFORM([1, 2, 3], a INT -> a * 2)"); | ||
| snowflake().verified_expr("TRANSFORM([1, 2, 3], (x INT, y INT) -> (x + y))"); | ||
| snowflake().verified_expr("REDUCE([1, 2, 3], 0, (acc, val) -> acc + val)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add test cases for FILTER as well?
|
@iffyio thanks for the feedback. I took a diff approach which I believe eliminates the concerns you raised. It's a bit of a shame that lambda expression parsing is spread across 3-4 diff flows but perhaps we can do something about it in the future. |
3ea5197 to
516a09d
Compare
iffyio
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @yoavcloud! Left some minor comments otherwise the changes look good to me!
| if self.peek_nth_token_ref(1).token == Token::Arrow | ||
| && self.dialect.supports_lambda_functions() => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if self.peek_nth_token_ref(1).token == Token::Arrow | |
| && self.dialect.supports_lambda_functions() => | |
| if self.dialect.supports_lambda_functions() && self.peek_nth_token_ref(1).token == Token::Arrow => |
thinking probably cleaner/quicker to first check the dialect before looking to parse any further?
| @@ -1051,6 +1052,7 @@ define_keywords!( | |||
| TRACE, | |||
| TRAILING, | |||
| TRANSACTION, | |||
| TRANSFORM, | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like both no longer need to be keywords in the diff?
This PR introduces the following changes:
TRANSFORM,FILTERandREDUCEfunctions which take lambda as an argument.See: https://docs.snowflake.com/en/user-guide/querying-semistructured#label-higher-order-functions