Skip to content
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

Update S3ToRedshift Operator docs to indicate multiple key functionality #28705

Merged
merged 1 commit into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion airflow/providers/amazon/aws/transfers/s3_to_redshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class S3ToRedshiftOperator(BaseOperator):
:param schema: reference to a specific schema in redshift database
:param table: reference to a specific table in redshift database
:param s3_bucket: reference to a specific S3 bucket
:param s3_key: reference to a specific S3 key
:param s3_key: key prefix that selects single or multiple objects from S3
:param redshift_conn_id: reference to a specific redshift database
:param aws_conn_id: reference to a specific S3 connection
If the AWS connection contains 'aws_iam_role' in ``extras``
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ Example usage:
:start-after: [START howto_transfer_s3_to_redshift]
:end-before: [END howto_transfer_s3_to_redshift]

Example of ingesting multiple keys:

.. exampleinclude:: /../../tests/system/providers/amazon/aws/example_redshift_s3_transfers.py
:language: python
:dedent: 4
:start-after: [START howto_transfer_s3_to_redshift_multiple_keys]
:end-before: [END howto_transfer_s3_to_redshift_multiple_keys]

You can find more information to the ``COPY`` command used
`here <https://docs.aws.amazon.com/us_en/redshift/latest/dg/copy-parameters-data-source-s3.html>`__.

Expand Down
14 changes: 14 additions & 0 deletions tests/system/providers/amazon/aws/example_redshift_s3_transfers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

S3_KEY = "s3_key"
S3_KEY_2 = "s3_key_2"
S3_KEY_PREFIX = "s3_"
REDSHIFT_TABLE = "test_table"

SQL_CREATE_TABLE = f"""
Expand Down Expand Up @@ -207,6 +208,18 @@ def delete_security_group(sec_group_id: str, sec_group_name: str):
)
# [END howto_transfer_s3_to_redshift]

# [START howto_transfer_s3_to_redshift_multiple_keys]
transfer_s3_to_redshift_multiple = S3ToRedshiftOperator(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont forget to add it to the chain command

task_id="transfer_s3_to_redshift_multiple",
redshift_conn_id=conn_id_name,
s3_bucket=bucket_name,
s3_key=S3_KEY_PREFIX,
schema="PUBLIC",
table=REDSHIFT_TABLE,
copy_options=["csv"],
)
# [END howto_transfer_s3_to_redshift_multiple_keys]

drop_table = RedshiftSQLOperator(
task_id="drop_table",
redshift_conn_id=conn_id_name,
Expand Down Expand Up @@ -246,6 +259,7 @@ def delete_security_group(sec_group_id: str, sec_group_name: str):
transfer_redshift_to_s3,
check_if_key_exists,
transfer_s3_to_redshift,
transfer_s3_to_redshift_multiple,
# TEST TEARDOWN
drop_table,
delete_cluster,
Expand Down