Skip to content

Snowflake: Lambda functions#2192

Open
yoavcloud wants to merge 3 commits intoapache:mainfrom
yoavcloud:sf_lambda_funcs
Open

Snowflake: Lambda functions#2192
yoavcloud wants to merge 3 commits intoapache:mainfrom
yoavcloud:sf_lambda_funcs

Conversation

@yoavcloud
Copy link
Contributor

This PR introduces the following changes:

  1. Enabled Lambda function support for the Snowflake dialect
  2. Expanded the Lambda struct to include an optional data type
  3. Added support for parsing the Snowflake TRANSFORM, FILTER and REDUCE functions which take lambda as an argument.

See: https://docs.snowflake.com/en/user-guide/querying-semistructured#label-higher-order-functions

Keyword::FILTER
| Keyword::TRANSFORM
| Keyword::REDUCE if self.dialect.supports_lambda_functions() => {
self.expect_token(&Token::LParen)?;
Copy link
Contributor

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>,
Copy link
Contributor

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?

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)");
Copy link
Contributor

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?

@yoavcloud
Copy link
Contributor Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants