Skip to content

Change tag and policy names to ObjectName instead of Ident #1892

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ast/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ pub struct ColumnPolicyProperty {
/// ```
/// [Snowflake]: https://docs.snowflake.com/en/sql-reference/sql/create-table
pub with: bool,
pub policy_name: Ident,
pub policy_name: ObjectName,
pub using_columns: Option<Vec<Ident>>,
}

Expand Down
4 changes: 2 additions & 2 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9206,12 +9206,12 @@ impl Display for RowAccessPolicy {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct Tag {
pub key: Ident,
pub key: ObjectName,
pub value: String,
}

impl Tag {
pub fn new(key: Ident, value: String) -> Self {
pub fn new(key: ObjectName, value: String) -> Self {
Self { key, value }
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/dialect/snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ fn parse_column_policy_property(
parser: &mut Parser,
with: bool,
) -> Result<ColumnPolicyProperty, ParserError> {
let policy_name = parser.parse_identifier()?;
let policy_name = parser.parse_object_name(false)?;
let using_columns = if parser.parse_keyword(Keyword::USING) {
parser.expect_token(&Token::LParen)?;
let columns = parser.parse_comma_separated(|p| p.parse_identifier())?;
Expand Down
2 changes: 1 addition & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7866,7 +7866,7 @@ impl<'a> Parser<'a> {
}

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

Expand Down
50 changes: 34 additions & 16 deletions tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ fn test_snowflake_create_table_with_tag() {
assert_eq!("my_table", name.to_string());
assert_eq!(
Some(vec![
Tag::new("A".into(), "TAG A".to_string()),
Tag::new("B".into(), "TAG B".to_string())
Tag::new(ObjectName::from(vec![Ident::new("A")]), "TAG A".to_string()),
Tag::new(ObjectName::from(vec![Ident::new("B")]), "TAG B".to_string())
]),
with_tags
);
Expand All @@ -291,8 +291,8 @@ fn test_snowflake_create_table_with_tag() {
assert_eq!("my_table", name.to_string());
assert_eq!(
Some(vec![
Tag::new("A".into(), "TAG A".to_string()),
Tag::new("B".into(), "TAG B".to_string())
Tag::new(ObjectName::from(vec![Ident::new("A")]), "TAG A".to_string()),
Tag::new(ObjectName::from(vec![Ident::new("B")]), "TAG B".to_string())
]),
with_tags
);
Expand Down Expand Up @@ -731,7 +731,7 @@ fn test_snowflake_create_table_with_columns_masking_policy() {
option: ColumnOption::Policy(ColumnPolicy::MaskingPolicy(
ColumnPolicyProperty {
with,
policy_name: "p".into(),
policy_name: ObjectName::from(vec![Ident::new("p")]),
using_columns,
}
))
Expand Down Expand Up @@ -765,7 +765,7 @@ fn test_snowflake_create_table_with_columns_projection_policy() {
option: ColumnOption::Policy(ColumnPolicy::ProjectionPolicy(
ColumnPolicyProperty {
with,
policy_name: "p".into(),
policy_name: ObjectName::from(vec![Ident::new("p")]),
using_columns: None,
}
))
Expand Down Expand Up @@ -802,8 +802,14 @@ fn test_snowflake_create_table_with_columns_tags() {
option: ColumnOption::Tags(TagsColumnOption {
with,
tags: vec![
Tag::new("A".into(), "TAG A".into()),
Tag::new("B".into(), "TAG B".into()),
Tag::new(
ObjectName::from(vec![Ident::new("A")]),
"TAG A".into()
),
Tag::new(
ObjectName::from(vec![Ident::new("B")]),
"TAG B".into()
),
]
}),
}],
Expand Down Expand Up @@ -846,7 +852,7 @@ fn test_snowflake_create_table_with_several_column_options() {
option: ColumnOption::Policy(ColumnPolicy::MaskingPolicy(
ColumnPolicyProperty {
with: true,
policy_name: "p1".into(),
policy_name: ObjectName::from(vec![Ident::new("p1")]),
using_columns: Some(vec!["a".into(), "b".into()]),
}
)),
Expand All @@ -856,8 +862,14 @@ fn test_snowflake_create_table_with_several_column_options() {
option: ColumnOption::Tags(TagsColumnOption {
with: true,
tags: vec![
Tag::new("A".into(), "TAG A".into()),
Tag::new("B".into(), "TAG B".into()),
Tag::new(
ObjectName::from(vec![Ident::new("A")]),
"TAG A".into()
),
Tag::new(
ObjectName::from(vec![Ident::new("B")]),
"TAG B".into()
),
]
}),
}
Expand All @@ -878,7 +890,7 @@ fn test_snowflake_create_table_with_several_column_options() {
option: ColumnOption::Policy(ColumnPolicy::ProjectionPolicy(
ColumnPolicyProperty {
with: false,
policy_name: "p2".into(),
policy_name: ObjectName::from(vec![Ident::new("p2")]),
using_columns: None,
}
)),
Expand All @@ -888,8 +900,14 @@ fn test_snowflake_create_table_with_several_column_options() {
option: ColumnOption::Tags(TagsColumnOption {
with: false,
tags: vec![
Tag::new("C".into(), "TAG C".into()),
Tag::new("D".into(), "TAG D".into()),
Tag::new(
ObjectName::from(vec![Ident::new("C")]),
"TAG C".into()
),
Tag::new(
ObjectName::from(vec![Ident::new("D")]),
"TAG D".into()
),
]
}),
}
Expand Down Expand Up @@ -942,8 +960,8 @@ fn test_snowflake_create_iceberg_table_all_options() {
with_aggregation_policy.map(|name| name.to_string())
);
assert_eq!(Some(vec![
Tag::new("A".into(), "TAG A".into()),
Tag::new("B".into(), "TAG B".into()),
Tag::new(ObjectName::from(vec![Ident::new("A")]), "TAG A".into()),
Tag::new(ObjectName::from(vec![Ident::new("B")]), "TAG B".into()),
]), with_tags);

}
Expand Down