Skip to content

Commit 6691f31

Browse files
authored
Fix credentials parsing for redshift (#2262)
1 parent 915448c commit 6691f31

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/ast/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9217,6 +9217,9 @@ pub enum CopyLegacyOption {
92179217
TruncateColumns,
92189218
/// ZSTD
92199219
Zstd,
9220+
/// Redshift `CREDENTIALS 'auth-args'`
9221+
/// <https://docs.aws.amazon.com/redshift/latest/dg/copy-parameters-authorization.html>
9222+
Credentials(String),
92209223
}
92219224

92229225
impl fmt::Display for CopyLegacyOption {
@@ -9327,6 +9330,7 @@ impl fmt::Display for CopyLegacyOption {
93279330
}
93289331
TruncateColumns => write!(f, "TRUNCATECOLUMNS"),
93299332
Zstd => write!(f, "ZSTD"),
9333+
Credentials(s) => write!(f, "CREDENTIALS '{}'", value::escape_single_quote_string(s)),
93309334
}
93319335
}
93329336
}

src/parser/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11177,6 +11177,7 @@ impl<'a> Parser<'a> {
1117711177
Keyword::BZIP2,
1117811178
Keyword::CLEANPATH,
1117911179
Keyword::COMPUPDATE,
11180+
Keyword::CREDENTIALS,
1118011181
Keyword::CSV,
1118111182
Keyword::DATEFORMAT,
1118211183
Keyword::DELIMITER,
@@ -11234,6 +11235,9 @@ impl<'a> Parser<'a> {
1123411235
};
1123511236
CopyLegacyOption::CompUpdate { preset, enabled }
1123611237
}
11238+
Some(Keyword::CREDENTIALS) => {
11239+
CopyLegacyOption::Credentials(self.parse_literal_string()?)
11240+
}
1123711241
Some(Keyword::CSV) => CopyLegacyOption::Csv({
1123811242
let mut opts = vec![];
1123911243
while let Some(opt) =

tests/sqlparser_redshift.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,3 +467,10 @@ fn test_create_table_diststyle() {
467467
redshift().verified_stmt("CREATE TABLE t1 (c1 INT) DISTSTYLE KEY DISTKEY(c1)");
468468
redshift().verified_stmt("CREATE TABLE t1 (c1 INT) DISTSTYLE ALL");
469469
}
470+
471+
#[test]
472+
fn test_copy_credentials() {
473+
redshift().verified_stmt(
474+
"COPY t1 FROM 's3://bucket/file.csv' CREDENTIALS 'aws_access_key_id=AK;aws_secret_access_key=SK' CSV",
475+
);
476+
}

0 commit comments

Comments
 (0)