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.
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.
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.
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.
Thanks @yoavcloud! Left some minor comments otherwise the changes look good to me!
src/parser/mod.rs
Outdated
| if self.peek_nth_token_ref(1).token == Token::Arrow | ||
| && self.dialect.supports_lambda_functions() => |
There was a problem hiding this comment.
| 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?
src/keywords.rs
Outdated
| @@ -1051,6 +1052,7 @@ define_keywords!( | |||
| TRACE, | |||
| TRAILING, | |||
| TRANSACTION, | |||
| TRANSFORM, | |||
There was a problem hiding this comment.
it looks like both no longer need to be keywords in the diff?
516a09d to
e84e397
Compare
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