Skip to content

Commit 65a8ee5

Browse files
committed
Added encode, distkey, sortkey in attributes support for redshift
1 parent b3e176d commit 65a8ee5

5 files changed

Lines changed: 42 additions & 0 deletions

File tree

src/ast/ddl.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,6 +2001,21 @@ pub enum ColumnOption {
20012001
/// ```
20022002
/// [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/invisible-columns.html
20032003
Invisible,
2004+
/// Redshift specific: Column compression encoding
2005+
/// Syntax: `ENCODE encoding`
2006+
///
2007+
/// [Redshift]: https://docs.aws.amazon.com/redshift/latest/dg/c_Compression_encodings.html
2008+
Encode(Ident),
2009+
/// Redshift specific: Column-level `DISTKEY` attribute
2010+
/// Syntax: `DISTKEY`
2011+
///
2012+
/// [Redshift]: https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_TABLE_NEW.html
2013+
DistKey,
2014+
/// Redshift specific: Column-level `SORTKEY` attribute
2015+
/// Syntax: `SORTKEY`
2016+
///
2017+
/// [Redshift]: https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_TABLE_NEW.html
2018+
SortKey,
20042019
}
20052020

20062021
impl From<UniqueConstraint> for ColumnOption {
@@ -2150,6 +2165,9 @@ impl fmt::Display for ColumnOption {
21502165
Invisible => {
21512166
write!(f, "INVISIBLE")
21522167
}
2168+
Encode(encoding) => write!(f, "ENCODE {encoding}"),
2169+
DistKey => write!(f, "DISTKEY"),
2170+
SortKey => write!(f, "SORTKEY"),
21532171
}
21542172
}
21552173
}

src/ast/spans.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,9 @@ impl Spanned for ColumnOption {
825825
ColumnOption::Tags(..) => Span::empty(),
826826
ColumnOption::Srid(..) => Span::empty(),
827827
ColumnOption::Invisible => Span::empty(),
828+
ColumnOption::Encode(_) => Span::empty(),
829+
ColumnOption::DistKey => Span::empty(),
830+
ColumnOption::SortKey => Span::empty(),
828831
}
829832
}
830833
}

src/keywords.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ define_keywords!(
360360
EMPTYASNULL,
361361
ENABLE,
362362
ENABLE_SCHEMA_EVOLUTION,
363+
ENCODE,
363364
ENCODING,
364365
ENCRYPTED,
365366
ENCRYPTION,

src/parser/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9331,6 +9331,12 @@ impl<'a> Parser<'a> {
93319331
)))
93329332
} else if self.parse_keyword(Keyword::INVISIBLE) {
93339333
Ok(Some(ColumnOption::Invisible))
9334+
} else if self.parse_keyword(Keyword::ENCODE) {
9335+
Ok(Some(ColumnOption::Encode(self.parse_identifier()?)))
9336+
} else if self.parse_keyword(Keyword::DISTKEY) {
9337+
Ok(Some(ColumnOption::DistKey))
9338+
} else if self.parse_keyword(Keyword::SORTKEY) {
9339+
Ok(Some(ColumnOption::SortKey))
93349340
} else {
93359341
Ok(None)
93369342
}

tests/sqlparser_redshift.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,3 +500,17 @@ fn test_alter_table_alter_sortkey() {
500500
redshift().verified_stmt("ALTER TABLE users ALTER SORTKEY(created_at)");
501501
redshift().verified_stmt("ALTER TABLE users ALTER SORTKEY(c1, c2)");
502502
}
503+
504+
#[test]
505+
fn test_create_table_with_column_options() {
506+
// Column-level ENCODE, DISTKEY, SORTKEY
507+
redshift().verified_stmt(
508+
"CREATE TABLE player_activity (date DATE ENCODE raw DISTKEY NOT NULL, userid INTEGER ENCODE az64 NOT NULL) DISTSTYLE KEY SORTKEY(date, userid)",
509+
);
510+
511+
redshift().verified_stmt("CREATE TABLE t1 (c1 INT DISTKEY, c2 INT SORTKEY)");
512+
513+
redshift().verified_stmt(
514+
"CREATE TABLE t1 (c1 INT ENCODE az64 NOT NULL, c2 VARCHAR(100) ENCODE lzo DEFAULT 'x')",
515+
);
516+
}

0 commit comments

Comments
 (0)