-
Notifications
You must be signed in to change notification settings - Fork 633
Redshift: UNLOAD #2013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yoavcloud
wants to merge
1
commit into
apache:main
Choose a base branch
from
yoavcloud:redshift_unload_stmt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Redshift: UNLOAD #2013
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4291,15 +4291,24 @@ pub enum Statement { | |||||
/// ``` | ||||||
/// Note: this is a MySQL-specific statement. See <https://dev.mysql.com/doc/refman/8.0/en/lock-tables.html> | ||||||
UnlockTables, | ||||||
/// Unloads the result of a query to file | ||||||
/// | ||||||
/// [Athena](https://docs.aws.amazon.com/athena/latest/ug/unload.html): | ||||||
/// ```sql | ||||||
/// UNLOAD(statement) TO <destination> [ WITH options ] | ||||||
/// ``` | ||||||
/// See Redshift <https://docs.aws.amazon.com/redshift/latest/dg/r_UNLOAD.html> and | ||||||
// Athena <https://docs.aws.amazon.com/athena/latest/ug/unload.html> | ||||||
/// | ||||||
/// [Redshift](https://docs.aws.amazon.com/redshift/latest/dg/r_UNLOAD.html): | ||||||
/// ```sql | ||||||
/// UNLOAD('statement') TO <destination> [ OPTIONS ] | ||||||
/// ``` | ||||||
Unload { | ||||||
query: Box<Query>, | ||||||
query: Option<Box<Query>>, | ||||||
query_text: Option<String>, | ||||||
to: Ident, | ||||||
auth: Option<IamRoleKind>, | ||||||
with: Vec<SqlOption>, | ||||||
options: Vec<CopyLegacyOption>, | ||||||
}, | ||||||
/// ```sql | ||||||
/// OPTIMIZE TABLE [db.]name [ON CLUSTER cluster] [PARTITION partition | PARTITION ID 'partition_id'] [FINAL] [DEDUPLICATE [BY expression]] | ||||||
|
@@ -6277,13 +6286,31 @@ impl fmt::Display for Statement { | |||||
Statement::UnlockTables => { | ||||||
write!(f, "UNLOCK TABLES") | ||||||
} | ||||||
Statement::Unload { query, to, with } => { | ||||||
write!(f, "UNLOAD({query}) TO {to}")?; | ||||||
|
||||||
Statement::Unload { | ||||||
query, | ||||||
query_text, | ||||||
to, | ||||||
auth, | ||||||
with, | ||||||
options, | ||||||
} => { | ||||||
write!(f, "UNLOAD(")?; | ||||||
if let Some(query) = query { | ||||||
write!(f, "{query}")?; | ||||||
} | ||||||
if let Some(query_text) = query_text { | ||||||
write!(f, "'{query_text}'")?; | ||||||
} | ||||||
write!(f, ") TO {to}")?; | ||||||
if let Some(auth) = auth { | ||||||
write!(f, " IAM_ROLE {auth}")?; | ||||||
} | ||||||
if !with.is_empty() { | ||||||
write!(f, " WITH ({})", display_comma_separated(with))?; | ||||||
} | ||||||
|
||||||
if !options.is_empty() { | ||||||
write!(f, " {}", display_separated(options, " "))?; | ||||||
} | ||||||
Ok(()) | ||||||
} | ||||||
Statement::OptimizeTable { | ||||||
|
@@ -8784,10 +8811,18 @@ pub enum CopyLegacyOption { | |||||
AcceptAnyDate, | ||||||
/// ACCEPTINVCHARS | ||||||
AcceptInvChars(Option<String>), | ||||||
/// ADDQUOTES | ||||||
AddQuotes, | ||||||
/// ALLOWOVERWRITE | ||||||
AllowOverwrite, | ||||||
/// BINARY | ||||||
Binary, | ||||||
/// BLANKSASNULL | ||||||
BlankAsNull, | ||||||
/// BZIP2 | ||||||
Bzip2, | ||||||
/// CLEANPATH | ||||||
CleanPath, | ||||||
/// CSV ... | ||||||
Csv(Vec<CopyLegacyCsvOption>), | ||||||
/// DATEFORMAT \[ AS \] {'dateformat_string' | 'auto' } | ||||||
|
@@ -8796,16 +8831,46 @@ pub enum CopyLegacyOption { | |||||
Delimiter(char), | ||||||
/// EMPTYASNULL | ||||||
EmptyAsNull, | ||||||
/// ENCRYPTED \[ AUTO \] | ||||||
Encrypted { auto: bool }, | ||||||
/// ESCAPE | ||||||
Escape, | ||||||
/// EXTENSION 'extension-name' | ||||||
Extension(String), | ||||||
/// FIXEDWIDTH \[ AS \] 'fixedwidth-spec' | ||||||
FixedWidth(String), | ||||||
/// GZIP | ||||||
Gzip, | ||||||
/// HEADER | ||||||
Header, | ||||||
/// IAM_ROLE { DEFAULT | 'arn:aws:iam::123456789:role/role1' } | ||||||
IamRole(IamRoleKind), | ||||||
/// IGNOREHEADER \[ AS \] number_rows | ||||||
IgnoreHeader(u64), | ||||||
/// JSON | ||||||
Json, | ||||||
/// MANIFEST \[ VERBOSE \] | ||||||
Manifest { verbose: bool }, | ||||||
/// MAXFILESIZE \[ AS \] max-size \[ MB | GB \] | ||||||
MaxFileSize(FileSize), | ||||||
/// NULL \[ AS \] 'null_string' | ||||||
Null(String), | ||||||
/// PARALLEL | ||||||
Parallel(Option<bool>), | ||||||
/// PARQUET | ||||||
Parquet, | ||||||
/// PARTITION BY ( column_name [, ... ] ) \[ INCLUDE \] | ||||||
PartitionBy(PartitionBy), | ||||||
/// REGION \[ AS \] 'aws-region' } | ||||||
Region(String), | ||||||
/// ROWGROUPSIZE \[ AS \] size \[ MB | GB \] | ||||||
RowGroupSize(FileSize), | ||||||
/// TIMEFORMAT \[ AS \] {'timeformat_string' | 'auto' | 'epochsecs' | 'epochmillisecs' } | ||||||
TimeFormat(Option<String>), | ||||||
/// TRUNCATECOLUMNS | ||||||
TruncateColumns, | ||||||
/// ZSTD | ||||||
Zstd, | ||||||
} | ||||||
|
||||||
impl fmt::Display for CopyLegacyOption { | ||||||
|
@@ -8820,8 +8885,12 @@ impl fmt::Display for CopyLegacyOption { | |||||
} | ||||||
Ok(()) | ||||||
} | ||||||
AddQuotes => write!(f, "ADDQUOTES"), | ||||||
AllowOverwrite => write!(f, "ALLOWOVERWRITE"), | ||||||
Binary => write!(f, "BINARY"), | ||||||
BlankAsNull => write!(f, "BLANKSASNULL"), | ||||||
Bzip2 => write!(f, "BZIP2"), | ||||||
CleanPath => write!(f, "CLEANPATH"), | ||||||
Csv(opts) => { | ||||||
write!(f, "CSV")?; | ||||||
if !opts.is_empty() { | ||||||
|
@@ -8838,9 +8907,37 @@ impl fmt::Display for CopyLegacyOption { | |||||
} | ||||||
Delimiter(char) => write!(f, "DELIMITER '{char}'"), | ||||||
EmptyAsNull => write!(f, "EMPTYASNULL"), | ||||||
Encrypted { auto } => write!(f, "ENCRYPTED{}", if *auto { " AUTO" } else { "" }), | ||||||
Escape => write!(f, "ESCAPE"), | ||||||
Extension(ext) => write!(f, "EXTENSION '{}'", value::escape_single_quote_string(ext)), | ||||||
FixedWidth(spec) => write!( | ||||||
f, | ||||||
"FIXEDWIDTH '{}'", | ||||||
value::escape_single_quote_string(spec) | ||||||
), | ||||||
Gzip => write!(f, "GZIP"), | ||||||
Header => write!(f, "HEADER"), | ||||||
IamRole(role) => write!(f, "IAM_ROLE {role}"), | ||||||
IgnoreHeader(num_rows) => write!(f, "IGNOREHEADER {num_rows}"), | ||||||
Json => write!(f, "JSON"), | ||||||
Manifest { verbose } => write!(f, "MANIFEST{}", if *verbose { " VERBOSE" } else { "" }), | ||||||
MaxFileSize(file_size) => write!(f, "MAXFILESIZE {file_size}"), | ||||||
Null(string) => write!(f, "NULL '{}'", value::escape_single_quote_string(string)), | ||||||
Parallel(enabled) => { | ||||||
write!( | ||||||
f, | ||||||
"PARALLEL{}", | ||||||
match enabled { | ||||||
Some(true) => " TRUE", | ||||||
Some(false) => " FALSE", | ||||||
_ => "", | ||||||
} | ||||||
) | ||||||
} | ||||||
Parquet => write!(f, "PARQUET"), | ||||||
PartitionBy(p) => write!(f, "{p}"), | ||||||
Region(region) => write!(f, "REGION '{}'", value::escape_single_quote_string(region)), | ||||||
RowGroupSize(file_size) => write!(f, "ROWGROUPSIZE {file_size}"), | ||||||
TimeFormat(fmt) => { | ||||||
write!(f, "TIMEFORMAT")?; | ||||||
if let Some(fmt) = fmt { | ||||||
|
@@ -8849,10 +8946,73 @@ impl fmt::Display for CopyLegacyOption { | |||||
Ok(()) | ||||||
} | ||||||
TruncateColumns => write!(f, "TRUNCATECOLUMNS"), | ||||||
Zstd => write!(f, "ZSTD"), | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
/// ```sql | ||||||
/// SIZE \[ MB | GB \] | ||||||
/// ``` | ||||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] | ||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] | ||||||
pub struct FileSize { | ||||||
pub size: Value, | ||||||
pub unit: Option<FileSizeUnit>, | ||||||
} | ||||||
|
||||||
impl fmt::Display for FileSize { | ||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||||
write!(f, "{}", self.size)?; | ||||||
if let Some(unit) = &self.unit { | ||||||
write!(f, " {unit}")?; | ||||||
} | ||||||
Ok(()) | ||||||
} | ||||||
} | ||||||
|
||||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] | ||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] | ||||||
pub enum FileSizeUnit { | ||||||
MB, | ||||||
GB, | ||||||
} | ||||||
|
||||||
impl fmt::Display for FileSizeUnit { | ||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||||
match self { | ||||||
FileSizeUnit::MB => write!(f, "MB"), | ||||||
FileSizeUnit::GB => write!(f, "GB"), | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
/// Specifies the partition keys for the unload operation | ||||||
/// | ||||||
/// ```sql | ||||||
/// PARTITION BY ( column_name [, ... ] ) [ INCLUDE ] | ||||||
/// ``` | ||||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] | ||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] | ||||||
pub struct PartitionBy { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Thinking since partitionby has meaning in other contexts? |
||||||
pub columns: Vec<Ident>, | ||||||
pub include: bool, | ||||||
} | ||||||
|
||||||
impl fmt::Display for PartitionBy { | ||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||||
write!( | ||||||
f, | ||||||
"PARTITION BY ({}){}", | ||||||
display_comma_separated(&self.columns), | ||||||
if self.include { " INCLUDE" } else { "" } | ||||||
) | ||||||
} | ||||||
} | ||||||
|
||||||
/// An `IAM_ROLE` option in the AWS ecosystem | ||||||
/// | ||||||
/// [Redshift COPY](https://docs.aws.amazon.com/redshift/latest/dg/copy-parameters-authorization.html#copy-iam-role) | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a description here to mention the behavior of on/off?