-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add UNLOAD macro * modifications to unload_table * remove unload from utilities * add docs; include schema arg * typo
- Loading branch information
1 parent
5ce4f7e
commit bbfcd8c
Showing
2 changed files
with
124 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
-- Redshift UNLOAD grammar (see: http://docs.aws.amazon.com/redshift/latest/dg/r_UNLOAD.html) | ||
{# | ||
UNLOAD ('select-statement') | ||
TO 's3://object-path/name-prefix' | ||
authorization | ||
[ option [ ... ] ] | ||
|
||
where option is | ||
|
||
{ MANIFEST | ||
| DELIMITER [ AS ] 'delimiter-char' | ||
| FIXEDWIDTH [ AS ] 'fixedwidth-spec' } | ||
| ENCRYPTED | ||
| BZIP2 | ||
| GZIP | ||
| ADDQUOTES | ||
| NULL [ AS ] 'null-string' | ||
| ESCAPE | ||
| ALLOWOVERWRITE | ||
| PARALLEL [ { ON | TRUE } | { OFF | FALSE } ] | ||
[ MAXFILESIZE [AS] max-size [ MB | GB ] ] | ||
|
||
#} | ||
-- Unloads a Redshift table to S3 | ||
{% macro unload_table(schema, | ||
table, | ||
s3_path, | ||
iam_role=None, | ||
aws_key=None, | ||
aws_secret=None, | ||
manifest=False, | ||
delimiter=",", | ||
null_as="", | ||
max_file_size='6 GB', | ||
escape=True, | ||
compression=None, | ||
add_quotes=False, | ||
encrypted=False, | ||
overwrite=False, | ||
parallel=False) %} | ||
|
||
-- compile UNLOAD statement | ||
UNLOAD ('SELECT * FROM "{{ schema }}"."{{ table }}"') | ||
TO '{{ s3_path }}' | ||
{% if iam_role %} | ||
IAM_ROLE '{{ iam_role }}' | ||
{% elif aws_key and aws_secret %} | ||
ACCESS_KEY_ID '{{ aws_key }}' | ||
SECRET_ACCESS_KEY '{{ aws_secret }}' | ||
{% else %} | ||
-- Raise an error if authorization args are not present | ||
{{ exceptions.raise_compiler_error("You must provide AWS authorization parameters via 'iam_role' or 'aws_key' and 'aws_secret'.") }} | ||
{% endif %} | ||
{% if manifest %} | ||
MANIFEST | ||
{% endif %} | ||
DELIMITER AS '{{ delimiter }}' | ||
NULL AS '{{ null_as }}' | ||
MAXFILESIZE AS {{ max_file_size }} | ||
{% if escape %} | ||
ESCAPE | ||
{% endif %} | ||
{% if compression %} | ||
{{ compression|upper }} | ||
{% endif %} | ||
{% if add_quotes %} | ||
ADDQUOTES | ||
{% endif %} | ||
{% if encrypted %} | ||
ENCRYPTED | ||
{% endif %} | ||
{% if overwrite %} | ||
ALLOWOVERWRITE | ||
{% endif %} | ||
{% if not parallel %} | ||
PARALLEL OFF | ||
{% endif %} | ||
|
||
{% endmacro %} |