7phs commented on code in PR #1454: URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1454#discussion_r1793277714
########## src/parser/mod.rs: ########## @@ -6193,24 +6186,160 @@ impl<'a> Parser<'a> { && dialect_of!(self is MySqlDialect | SQLiteDialect | DuckDbDialect | GenericDialect) { self.parse_optional_column_option_as() + } else if self.parse_keyword(Keyword::AUTOINCREMENT) + && dialect_of!(self is SnowflakeDialect | SQLiteDialect | GenericDialect) + { + if dialect_of!(self is SnowflakeDialect) { + self.prev_token(); + return self.parse_snowflake_autoincrement_or_identity_option_column(); + } + + // Support AUTOINCREMENT for SQLite + Ok(Some(ColumnOption::DialectSpecific(vec![ + Token::make_keyword("AUTOINCREMENT"), + ]))) } else if self.parse_keyword(Keyword::IDENTITY) - && dialect_of!(self is MsSqlDialect | GenericDialect) + && dialect_of!(self is MsSqlDialect | SnowflakeDialect | GenericDialect) { - let property = if self.consume_token(&Token::LParen) { + if dialect_of!(self is SnowflakeDialect) { + self.prev_token(); + return self.parse_snowflake_autoincrement_or_identity_option_column(); + } + + let parameters = if self.consume_token(&Token::LParen) { let seed = self.parse_number()?; self.expect_token(&Token::Comma)?; let increment = self.parse_number()?; self.expect_token(&Token::RParen)?; - Some(IdentityProperty { seed, increment }) + Some(IdentityFormat::FunctionCall(IdentityParameters { + seed, + increment, + })) } else { None }; - Ok(Some(ColumnOption::Identity(property))) + Ok(Some(ColumnOption::Identity(Identity::Identity( + IdentityProperty { + parameters, + order: None, + }, + )))) + } else if ((self.parse_keyword(Keyword::WITH) + && self + .parse_one_of_keywords(&[Keyword::MASKING, Keyword::PROJECTION]) + .is_some()) + || self + .parse_one_of_keywords(&[Keyword::MASKING, Keyword::PROJECTION]) + .is_some()) + && dialect_of!(self is SnowflakeDialect | GenericDialect) + { + self.prev_token(); + let Some(policy) = self.parse_snowflake_column_policy()? else { + return Ok(None); + }; + Ok(Some(ColumnOption::Policy(policy))) + } else if self.parse_keywords(&[Keyword::TAG]) + && dialect_of!(self is SnowflakeDialect | GenericDialect) + { + self.expect_token(&Token::LParen)?; + let tags = self.parse_comma_separated(Self::parse_tag)?; + self.expect_token(&Token::RParen)?; + + Ok(Some(ColumnOption::Tags(tags))) + } else { + Ok(None) + } + } + + fn parse_snowflake_autoincrement_or_identity_option_column( Review Comment: I added a reasonable documentation for structs with links to a Snowflake doc and moved this function into `snowflake` dialect implementation. ########## src/ast/ddl.rs: ########## @@ -1098,17 +1098,116 @@ impl fmt::Display for ColumnOptionDef { } } +#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] +pub enum Identity { + Autoincrement(IdentityProperty), + Identity(IdentityProperty), +} + #[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] pub struct IdentityProperty { + pub parameters: Option<IdentityFormat>, + pub order: Option<IdentityOrder>, +} + +#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] +pub enum IdentityFormat { + FunctionCall(IdentityParameters), + StartAndIncrement(IdentityParameters), +} + +#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] +pub struct IdentityParameters { pub seed: Expr, pub increment: Expr, } -impl fmt::Display for IdentityProperty { +#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] +pub enum IdentityOrder { + Order, + Noorder, Review Comment: Updated. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@datafusion.apache.org For additional commands, e-mail: dev-h...@datafusion.apache.org