Skip to content

Commit 9029256

Browse files
yoavcloudayman-sigma
authored andcommitted
Redshift: Add support for optional JSON format in copy option (apache#2141)
1 parent e97de4d commit 9029256

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

src/ast/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8330,8 +8330,8 @@ pub enum CopyLegacyOption {
83308330
IamRole(IamRoleKind),
83318331
/// IGNOREHEADER \[ AS \] number_rows
83328332
IgnoreHeader(u64),
8333-
/// JSON
8334-
Json,
8333+
/// JSON \[ AS \] 'json_option'
8334+
Json(Option<String>),
83358335
/// MANIFEST \[ VERBOSE \]
83368336
Manifest { verbose: bool },
83378337
/// MAXFILESIZE \[ AS \] max-size \[ MB | GB \]
@@ -8422,7 +8422,13 @@ impl fmt::Display for CopyLegacyOption {
84228422
Header => write!(f, "HEADER"),
84238423
IamRole(role) => write!(f, "IAM_ROLE {role}"),
84248424
IgnoreHeader(num_rows) => write!(f, "IGNOREHEADER {num_rows}"),
8425-
Json => write!(f, "JSON"),
8425+
Json(opt) => {
8426+
write!(f, "JSON")?;
8427+
if let Some(opt) = opt {
8428+
write!(f, " AS '{}'", value::escape_single_quote_string(opt))?;
8429+
}
8430+
Ok(())
8431+
}
84268432
Manifest { verbose } => write!(f, "MANIFEST{}", if *verbose { " VERBOSE" } else { "" }),
84278433
MaxFileSize(file_size) => write!(f, "MAXFILESIZE {file_size}"),
84288434
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
@@ -10778,7 +10778,15 @@ impl<'a> Parser<'a> {
1077810778
let num_rows = self.parse_literal_uint()?;
1077910779
CopyLegacyOption::IgnoreHeader(num_rows)
1078010780
}
10781-
Some(Keyword::JSON) => CopyLegacyOption::Json,
10781+
Some(Keyword::JSON) => {
10782+
let _ = self.parse_keyword(Keyword::AS);
10783+
let fmt = if matches!(self.peek_token().token, Token::SingleQuotedString(_)) {
10784+
Some(self.parse_literal_string()?)
10785+
} else {
10786+
None
10787+
};
10788+
CopyLegacyOption::Json(fmt)
10789+
}
1078210790
Some(Keyword::MANIFEST) => {
1078310791
let verbose = self.parse_keyword(Keyword::VERBOSE);
1078410792
CopyLegacyOption::Manifest { verbose }

tests/sqlparser_common.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17447,6 +17447,9 @@ fn parse_copy_options() {
1744717447
"EMPTYASNULL ",
1744817448
"IAM_ROLE DEFAULT ",
1744917449
"IGNOREHEADER AS 1 ",
17450+
"JSON ",
17451+
"JSON 'auto' ",
17452+
"JSON AS 'auto' ",
1745017453
"TIMEFORMAT AS 'auto' ",
1745117454
"TRUNCATECOLUMNS ",
1745217455
"REMOVEQUOTES ",
@@ -17472,6 +17475,9 @@ fn parse_copy_options() {
1747217475
"EMPTYASNULL ",
1747317476
"IAM_ROLE DEFAULT ",
1747417477
"IGNOREHEADER 1 ",
17478+
"JSON ",
17479+
"JSON AS 'auto' ",
17480+
"JSON AS 'auto' ",
1747517481
"TIMEFORMAT 'auto' ",
1747617482
"TRUNCATECOLUMNS ",
1747717483
"REMOVEQUOTES ",

0 commit comments

Comments
 (0)