Skip to content

Commit d80c0b9

Browse files
authored
Redshift: Add support for optional JSON format in copy option (#2141)
1 parent 3af9988 commit d80c0b9

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/ast/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8296,8 +8296,8 @@ pub enum CopyLegacyOption {
82968296
IamRole(IamRoleKind),
82978297
/// IGNOREHEADER \[ AS \] number_rows
82988298
IgnoreHeader(u64),
8299-
/// JSON
8300-
Json,
8299+
/// JSON \[ AS \] 'json_option'
8300+
Json(Option<String>),
83018301
/// MANIFEST \[ VERBOSE \]
83028302
Manifest { verbose: bool },
83038303
/// MAXFILESIZE \[ AS \] max-size \[ MB | GB \]
@@ -8388,7 +8388,13 @@ impl fmt::Display for CopyLegacyOption {
83888388
Header => write!(f, "HEADER"),
83898389
IamRole(role) => write!(f, "IAM_ROLE {role}"),
83908390
IgnoreHeader(num_rows) => write!(f, "IGNOREHEADER {num_rows}"),
8391-
Json => write!(f, "JSON"),
8391+
Json(opt) => {
8392+
write!(f, "JSON")?;
8393+
if let Some(opt) = opt {
8394+
write!(f, " AS '{}'", value::escape_single_quote_string(opt))?;
8395+
}
8396+
Ok(())
8397+
}
83928398
Manifest { verbose } => write!(f, "MANIFEST{}", if *verbose { " VERBOSE" } else { "" }),
83938399
MaxFileSize(file_size) => write!(f, "MAXFILESIZE {file_size}"),
83948400
Null(string) => write!(f, "NULL '{}'", value::escape_single_quote_string(string)),

src/parser/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10747,7 +10747,15 @@ impl<'a> Parser<'a> {
1074710747
let num_rows = self.parse_literal_uint()?;
1074810748
CopyLegacyOption::IgnoreHeader(num_rows)
1074910749
}
10750-
Some(Keyword::JSON) => CopyLegacyOption::Json,
10750+
Some(Keyword::JSON) => {
10751+
let _ = self.parse_keyword(Keyword::AS);
10752+
let fmt = if matches!(self.peek_token().token, Token::SingleQuotedString(_)) {
10753+
Some(self.parse_literal_string()?)
10754+
} else {
10755+
None
10756+
};
10757+
CopyLegacyOption::Json(fmt)
10758+
}
1075110759
Some(Keyword::MANIFEST) => {
1075210760
let verbose = self.parse_keyword(Keyword::VERBOSE);
1075310761
CopyLegacyOption::Manifest { verbose }

tests/sqlparser_common.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17421,6 +17421,9 @@ fn parse_copy_options() {
1742117421
"EMPTYASNULL ",
1742217422
"IAM_ROLE DEFAULT ",
1742317423
"IGNOREHEADER AS 1 ",
17424+
"JSON ",
17425+
"JSON 'auto' ",
17426+
"JSON AS 'auto' ",
1742417427
"TIMEFORMAT AS 'auto' ",
1742517428
"TRUNCATECOLUMNS ",
1742617429
"REMOVEQUOTES ",
@@ -17446,6 +17449,9 @@ fn parse_copy_options() {
1744617449
"EMPTYASNULL ",
1744717450
"IAM_ROLE DEFAULT ",
1744817451
"IGNOREHEADER 1 ",
17452+
"JSON ",
17453+
"JSON AS 'auto' ",
17454+
"JSON AS 'auto' ",
1744917455
"TIMEFORMAT 'auto' ",
1745017456
"TRUNCATECOLUMNS ",
1745117457
"REMOVEQUOTES ",

0 commit comments

Comments
 (0)