Skip to content

Commit 36cf0bf

Browse files
feat(snowflake)!: annotation support for CURRENT_ROLE. (#6478)
* feat(snowflake)!: annotation support for CURRENT_ROLE. Return type VARCHAR * feat(snowflake)!: adding tests to mysql and postgres.annotation support for CURRENT_ROLE. Return type VARCHAR * feat(snowflake)!: adding tests to mysql and postgres.annotation support for CURRENT_ROLE. Return type VARCHAR added current_role to no_paren list --------- Co-authored-by: Jo <46752250+georgesittas@users.noreply.github.com>
1 parent 36ad534 commit 36cf0bf

File tree

8 files changed

+14
-0
lines changed

8 files changed

+14
-0
lines changed

sqlglot/expressions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6360,6 +6360,10 @@ class CurrentRegion(Func):
63606360
arg_types = {}
63616361

63626362

6363+
class CurrentRole(Func):
6364+
arg_types = {}
6365+
6366+
63636367
class CurrentRoleType(Func):
63646368
arg_types = {}
63656369

sqlglot/parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ class Parser(metaclass=_Parser):
291291
TokenType.CURRENT_USER: exp.CurrentUser,
292292
TokenType.LOCALTIME: exp.Localtime,
293293
TokenType.LOCALTIMESTAMP: exp.Localtimestamp,
294+
TokenType.CURRENT_ROLE: exp.CurrentRole,
294295
}
295296

296297
STRUCT_TYPE_TOKENS = {

sqlglot/tokens.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ class TokenType(AutoName):
276276
CURRENT_TIME = auto()
277277
CURRENT_TIMESTAMP = auto()
278278
CURRENT_USER = auto()
279+
CURRENT_ROLE = auto()
279280
DECLARE = auto()
280281
DEFAULT = auto()
281282
DELETE = auto()

sqlglot/typing/snowflake.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ def _annotate_math_with_float_decfloat(
375375
exp.Collation,
376376
exp.CurrentOrganizationUser,
377377
exp.CurrentRegion,
378+
exp.CurrentRole,
378379
exp.CurrentRoleType,
379380
exp.CurrentOrganizationName,
380381
exp.DecompressString,

tests/dialects/test_mysql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ def test_identity(self):
214214
self.validate_identity("""SELECT 'ab' MEMBER OF('[23, "abc", 17, "ab", 10]')""")
215215
self.validate_identity("""SELECT * FROM foo WHERE 'ab' MEMBER OF(content)""")
216216
self.validate_identity("SELECT CURRENT_TIMESTAMP(6)")
217+
self.validate_identity("SELECT CURRENT_ROLE()")
217218
self.validate_identity("x ->> '$.name'")
218219
self.validate_identity("SELECT CAST(`a`.`b` AS CHAR) FROM foo")
219220
self.validate_identity("SELECT TRIM(LEADING 'bla' FROM ' XXX ')")

tests/dialects/test_postgres.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def test_postgres(self):
7979
self.validate_identity("EXEC AS myfunc @id = 123", check_command_warning=True)
8080
self.validate_identity("SELECT CURRENT_SCHEMA")
8181
self.validate_identity("SELECT CURRENT_USER")
82+
self.validate_identity("SELECT CURRENT_ROLE")
8283
self.validate_identity("SELECT * FROM ONLY t1")
8384
self.validate_identity("SELECT INTERVAL '-1 MONTH'")
8485
self.validate_identity("SELECT INTERVAL '4.1 DAY'")

tests/dialects/test_snowflake.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def test_snowflake(self):
243243
self.validate_identity("SELECT OBJECT_CONSTRUCT()")
244244
self.validate_identity("SELECT CURRENT_ORGANIZATION_USER()")
245245
self.validate_identity("SELECT CURRENT_REGION()")
246+
self.validate_identity("SELECT CURRENT_ROLE()")
246247
self.validate_identity("SELECT CURRENT_ROLE_TYPE()")
247248
self.validate_identity("SELECT YEAR(CURRENT_TIMESTAMP())")
248249
self.validate_identity("SELECT YEAROFWEEK(CURRENT_TIMESTAMP())")

tests/fixtures/optimizer/annotate_functions.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,6 +2284,10 @@ VARCHAR;
22842284
CURRENT_REGION();
22852285
VARCHAR;
22862286

2287+
# dialect: snowflake
2288+
CURRENT_ROLE();
2289+
VARCHAR;
2290+
22872291
# dialect: snowflake
22882292
CURRENT_ROLE_TYPE();
22892293
VARCHAR;

0 commit comments

Comments
 (0)