-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(snowflake)!: annotate types for MAP_* functions #6605
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
SQLGlot Integration Test ResultsComparing:
By Dialect
Overallmain: 2170 total, 1596 passed (pass rate: 73.5%), sqlglot version: sqlglot:feature/annotatetype-map_functions: 2170 total, 1597 passed (pass rate: 73.6%), sqlglot version: Difference: No change |
| self.validate_identity("SELECT rename, replace") | ||
| self.validate_identity("SELECT TIMEADD(HOUR, 2, CAST('09:05:03' AS TIME))") | ||
| self.validate_identity("SELECT CAST(OBJECT_CONSTRUCT('a', 1) AS MAP(VARCHAR, INT))") | ||
| self.validate_identity( |
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.
nit: maybe simplify these statements a bit for readability, we probably don't need multi-item maps for most operations
geooo109
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.
Did you also check if other databases support these functions ?
| class MapCat(Func): | ||
| arg_types = {"this": True, "expressions": False} | ||
| is_var_len_args = True |
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.
Why is this a multi-argument Func? Snowflake's docs specify two arguments:
MAP_CAT( <map1> , <map2> )
| class MapDelete(Func): | ||
| arg_types = {"this": True, "expressions": False} | ||
| is_var_len_args = True |
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.
The expressions arg should be mandatory, MAP_DELETE always requires at least one key:
MAP_DELETE( <map>, <key1> [, <key2>, ... ] )
| class MapInsert(Func): | ||
| arg_types = {"this": True, "expressions": False} | ||
| is_var_len_args = True |
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.
We should have more fine-grained arguments for this:
MAP_INSERT( <map> , <key> , <value> [ , <updateFlag> ] )
Let's do this, key, value, update_flag (optional).
| class MapPick(Func): | ||
| arg_types = {"this": True, "expressions": False} | ||
| is_var_len_args = True |
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.
Ditto re: expressions becomine True.
Documentation:
https://docs.snowflake.com/en/sql-reference/functions/map_cat
https://docs.snowflake.com/en/sql-reference/functions/map_contains_key
https://docs.snowflake.com/en/sql-reference/functions/map_delete
https://docs.snowflake.com/en/sql-reference/functions/map_insert
https://docs.snowflake.com/en/sql-reference/functions/map_keys
https://docs.snowflake.com/en/sql-reference/functions/map_pick
https://docs.snowflake.com/en/sql-reference/functions/map_size