Skip to content

Commit a0165e3

Browse files
committed
Redshift: Add support for optional JSON format in copy option
1 parent 14703f0 commit a0165e3

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
@@ -10621,7 +10621,15 @@ impl<'a> Parser<'a> {
1062110621
let num_rows = self.parse_literal_uint()?;
1062210622
CopyLegacyOption::IgnoreHeader(num_rows)
1062310623
}
10624-
Some(Keyword::JSON) => CopyLegacyOption::Json,
10624+
Some(Keyword::JSON) => {
10625+
let _ = self.parse_keyword(Keyword::AS);
10626+
let fmt = if matches!(self.peek_token().token, Token::SingleQuotedString(_)) {
10627+
Some(self.parse_literal_string()?)
10628+
} else {
10629+
None
10630+
};
10631+
CopyLegacyOption::Json(fmt)
10632+
}
1062510633
Some(Keyword::MANIFEST) => {
1062610634
let verbose = self.parse_keyword(Keyword::VERBOSE);
1062710635
CopyLegacyOption::Manifest { verbose }

tests/sqlparser_common.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17398,6 +17398,9 @@ fn parse_copy_options() {
1739817398
"EMPTYASNULL ",
1739917399
"IAM_ROLE DEFAULT ",
1740017400
"IGNOREHEADER AS 1 ",
17401+
"JSON ",
17402+
"JSON 'auto' ",
17403+
"JSON AS 'auto' ",
1740117404
"TIMEFORMAT AS 'auto' ",
1740217405
"TRUNCATECOLUMNS ",
1740317406
"REMOVEQUOTES ",
@@ -17423,6 +17426,9 @@ fn parse_copy_options() {
1742317426
"EMPTYASNULL ",
1742417427
"IAM_ROLE DEFAULT ",
1742517428
"IGNOREHEADER 1 ",
17429+
"JSON ",
17430+
"JSON AS 'auto' ",
17431+
"JSON AS 'auto' ",
1742617432
"TIMEFORMAT 'auto' ",
1742717433
"TRUNCATECOLUMNS ",
1742817434
"REMOVEQUOTES ",

0 commit comments

Comments
 (0)