Skip to content

Commit 05fe847

Browse files
authored
Fix(snowflake): support fqns in masking/projection policy constraint (#3620)
1 parent 5396a8e commit 05fe847

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

sqlglot/dialects/snowflake.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,15 +510,18 @@ def _parse_with_constraint(self) -> t.Optional[exp.Expression]:
510510
self._retreat(self._index - 1)
511511

512512
if self._match_text_seq("MASKING", "POLICY"):
513+
policy = self._parse_column()
513514
return self.expression(
514515
exp.MaskingPolicyColumnConstraint,
515-
this=self._parse_id_var(),
516+
this=policy.to_dot() if isinstance(policy, exp.Column) else policy,
516517
expressions=self._match(TokenType.USING)
517518
and self._parse_wrapped_csv(self._parse_id_var),
518519
)
519520
if self._match_text_seq("PROJECTION", "POLICY"):
521+
policy = self._parse_column()
520522
return self.expression(
521-
exp.ProjectionPolicyColumnConstraint, this=self._parse_id_var()
523+
exp.ProjectionPolicyColumnConstraint,
524+
this=policy.to_dot() if isinstance(policy, exp.Column) else policy,
522525
)
523526
if self._match(TokenType.TAG):
524527
return self.expression(

tests/dialects/test_snowflake.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,16 +1196,16 @@ def test_ddl(self):
11961196
for constraint_prefix in ("WITH ", ""):
11971197
with self.subTest(f"Constraint prefix: {constraint_prefix}"):
11981198
self.validate_identity(
1199-
f"CREATE TABLE t (id INT {constraint_prefix}MASKING POLICY p)",
1200-
"CREATE TABLE t (id INT MASKING POLICY p)",
1199+
f"CREATE TABLE t (id INT {constraint_prefix}MASKING POLICY p.q.r)",
1200+
"CREATE TABLE t (id INT MASKING POLICY p.q.r)",
12011201
)
12021202
self.validate_identity(
12031203
f"CREATE TABLE t (id INT {constraint_prefix}MASKING POLICY p USING (c1, c2, c3))",
12041204
"CREATE TABLE t (id INT MASKING POLICY p USING (c1, c2, c3))",
12051205
)
12061206
self.validate_identity(
1207-
f"CREATE TABLE t (id INT {constraint_prefix}PROJECTION POLICY p)",
1208-
"CREATE TABLE t (id INT PROJECTION POLICY p)",
1207+
f"CREATE TABLE t (id INT {constraint_prefix}PROJECTION POLICY p.q.r)",
1208+
"CREATE TABLE t (id INT PROJECTION POLICY p.q.r)",
12091209
)
12101210
self.validate_identity(
12111211
f"CREATE TABLE t (id INT {constraint_prefix}TAG (key1='value_1', key2='value_2'))",

0 commit comments

Comments
 (0)