Skip to content

Commit 942d747

Browse files
Change tag and policy names to ObjectName (#1892)
1 parent 239e30a commit 942d747

File tree

5 files changed

+53
-21
lines changed

5 files changed

+53
-21
lines changed

src/ast/ddl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,7 @@ pub struct ColumnPolicyProperty {
17091709
/// ```
17101710
/// [Snowflake]: https://docs.snowflake.com/en/sql-reference/sql/create-table
17111711
pub with: bool,
1712-
pub policy_name: Ident,
1712+
pub policy_name: ObjectName,
17131713
pub using_columns: Option<Vec<Ident>>,
17141714
}
17151715

src/ast/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9372,12 +9372,12 @@ impl Display for RowAccessPolicy {
93729372
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
93739373
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
93749374
pub struct Tag {
9375-
pub key: Ident,
9375+
pub key: ObjectName,
93769376
pub value: String,
93779377
}
93789378

93799379
impl Tag {
9380-
pub fn new(key: Ident, value: String) -> Self {
9380+
pub fn new(key: ObjectName, value: String) -> Self {
93819381
Self { key, value }
93829382
}
93839383
}

src/dialect/snowflake.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ fn parse_column_policy_property(
11891189
parser: &mut Parser,
11901190
with: bool,
11911191
) -> Result<ColumnPolicyProperty, ParserError> {
1192-
let policy_name = parser.parse_identifier()?;
1192+
let policy_name = parser.parse_object_name(false)?;
11931193
let using_columns = if parser.parse_keyword(Keyword::USING) {
11941194
parser.expect_token(&Token::LParen)?;
11951195
let columns = parser.parse_comma_separated(|p| p.parse_identifier())?;

src/parser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7884,7 +7884,7 @@ impl<'a> Parser<'a> {
78847884
}
78857885

78867886
pub(crate) fn parse_tag(&mut self) -> Result<Tag, ParserError> {
7887-
let name = self.parse_identifier()?;
7887+
let name = self.parse_object_name(false)?;
78887888
self.expect_token(&Token::Eq)?;
78897889
let value = self.parse_literal_string()?;
78907890

tests/sqlparser_snowflake.rs

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ fn test_snowflake_create_table_with_tag() {
270270
assert_eq!("my_table", name.to_string());
271271
assert_eq!(
272272
Some(vec![
273-
Tag::new("A".into(), "TAG A".to_string()),
274-
Tag::new("B".into(), "TAG B".to_string())
273+
Tag::new(ObjectName::from(vec![Ident::new("A")]), "TAG A".to_string()),
274+
Tag::new(ObjectName::from(vec![Ident::new("B")]), "TAG B".to_string())
275275
]),
276276
with_tags
277277
);
@@ -291,8 +291,8 @@ fn test_snowflake_create_table_with_tag() {
291291
assert_eq!("my_table", name.to_string());
292292
assert_eq!(
293293
Some(vec![
294-
Tag::new("A".into(), "TAG A".to_string()),
295-
Tag::new("B".into(), "TAG B".to_string())
294+
Tag::new(ObjectName::from(vec![Ident::new("A")]), "TAG A".to_string()),
295+
Tag::new(ObjectName::from(vec![Ident::new("B")]), "TAG B".to_string())
296296
]),
297297
with_tags
298298
);
@@ -731,7 +731,7 @@ fn test_snowflake_create_table_with_columns_masking_policy() {
731731
option: ColumnOption::Policy(ColumnPolicy::MaskingPolicy(
732732
ColumnPolicyProperty {
733733
with,
734-
policy_name: "p".into(),
734+
policy_name: ObjectName::from(vec![Ident::new("p")]),
735735
using_columns,
736736
}
737737
))
@@ -765,7 +765,7 @@ fn test_snowflake_create_table_with_columns_projection_policy() {
765765
option: ColumnOption::Policy(ColumnPolicy::ProjectionPolicy(
766766
ColumnPolicyProperty {
767767
with,
768-
policy_name: "p".into(),
768+
policy_name: ObjectName::from(vec![Ident::new("p")]),
769769
using_columns: None,
770770
}
771771
))
@@ -802,8 +802,14 @@ fn test_snowflake_create_table_with_columns_tags() {
802802
option: ColumnOption::Tags(TagsColumnOption {
803803
with,
804804
tags: vec![
805-
Tag::new("A".into(), "TAG A".into()),
806-
Tag::new("B".into(), "TAG B".into()),
805+
Tag::new(
806+
ObjectName::from(vec![Ident::new("A")]),
807+
"TAG A".into()
808+
),
809+
Tag::new(
810+
ObjectName::from(vec![Ident::new("B")]),
811+
"TAG B".into()
812+
),
807813
]
808814
}),
809815
}],
@@ -846,7 +852,7 @@ fn test_snowflake_create_table_with_several_column_options() {
846852
option: ColumnOption::Policy(ColumnPolicy::MaskingPolicy(
847853
ColumnPolicyProperty {
848854
with: true,
849-
policy_name: "p1".into(),
855+
policy_name: ObjectName::from(vec![Ident::new("p1")]),
850856
using_columns: Some(vec!["a".into(), "b".into()]),
851857
}
852858
)),
@@ -856,8 +862,14 @@ fn test_snowflake_create_table_with_several_column_options() {
856862
option: ColumnOption::Tags(TagsColumnOption {
857863
with: true,
858864
tags: vec![
859-
Tag::new("A".into(), "TAG A".into()),
860-
Tag::new("B".into(), "TAG B".into()),
865+
Tag::new(
866+
ObjectName::from(vec![Ident::new("A")]),
867+
"TAG A".into()
868+
),
869+
Tag::new(
870+
ObjectName::from(vec![Ident::new("B")]),
871+
"TAG B".into()
872+
),
861873
]
862874
}),
863875
}
@@ -878,7 +890,7 @@ fn test_snowflake_create_table_with_several_column_options() {
878890
option: ColumnOption::Policy(ColumnPolicy::ProjectionPolicy(
879891
ColumnPolicyProperty {
880892
with: false,
881-
policy_name: "p2".into(),
893+
policy_name: ObjectName::from(vec![Ident::new("p2")]),
882894
using_columns: None,
883895
}
884896
)),
@@ -888,8 +900,14 @@ fn test_snowflake_create_table_with_several_column_options() {
888900
option: ColumnOption::Tags(TagsColumnOption {
889901
with: false,
890902
tags: vec![
891-
Tag::new("C".into(), "TAG C".into()),
892-
Tag::new("D".into(), "TAG D".into()),
903+
Tag::new(
904+
ObjectName::from(vec![Ident::new("C")]),
905+
"TAG C".into()
906+
),
907+
Tag::new(
908+
ObjectName::from(vec![Ident::new("D")]),
909+
"TAG D".into()
910+
),
893911
]
894912
}),
895913
}
@@ -942,8 +960,8 @@ fn test_snowflake_create_iceberg_table_all_options() {
942960
with_aggregation_policy.map(|name| name.to_string())
943961
);
944962
assert_eq!(Some(vec![
945-
Tag::new("A".into(), "TAG A".into()),
946-
Tag::new("B".into(), "TAG B".into()),
963+
Tag::new(ObjectName::from(vec![Ident::new("A")]), "TAG A".into()),
964+
Tag::new(ObjectName::from(vec![Ident::new("B")]), "TAG B".into()),
947965
]), with_tags);
948966

949967
}
@@ -4172,3 +4190,17 @@ fn test_snowflake_create_view_with_multiple_column_options() {
41724190
r#"CREATE VIEW X (COL WITH TAG (pii='email') COMMENT 'foobar') AS SELECT * FROM Y"#;
41734191
snowflake().verified_stmt(create_view_with_tag);
41744192
}
4193+
4194+
#[test]
4195+
fn test_snowflake_create_view_with_composite_tag() {
4196+
let create_view_with_tag =
4197+
r#"CREATE VIEW X (COL WITH TAG (foo.bar.baz.pii='email')) AS SELECT * FROM Y"#;
4198+
snowflake().verified_stmt(create_view_with_tag);
4199+
}
4200+
4201+
#[test]
4202+
fn test_snowflake_create_view_with_composite_policy_name() {
4203+
let create_view_with_tag =
4204+
r#"CREATE VIEW X (COL WITH MASKING POLICY foo.bar.baz) AS SELECT * FROM Y"#;
4205+
snowflake().verified_stmt(create_view_with_tag);
4206+
}

0 commit comments

Comments
 (0)