SatishChGit commented on code in PR #39217: URL: https://github.com/apache/airflow/pull/39217#discussion_r1589544440
########## tests/system/providers/teradata/example_s3_to_teradata_transfer.py: ########## @@ -0,0 +1,163 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +""" +Example Airflow DAG to show usage of S3StorageToTeradataOperator. + +The transfer operator moves files in CSV, JSON, and PARQUET formats from S3 +to Teradata tables. In the example Directed Acyclic Graph (DAG) below, it assumes Airflow +Connections with the IDs `teradata_default` and `aws_default` already exist. The DAG creates +tables using data from the S3, reports the number of rows inserted into +the table, and subsequently drops the table. +""" + +from __future__ import annotations + +import datetime +import os + +import pytest + +from airflow import DAG +from airflow.providers.teradata.transfers.s3_to_teradata import S3ToTeradataOperator + +try: + from airflow.providers.teradata.operators.teradata import TeradataOperator +except ImportError: + pytest.skip("Teradata provider apache-airflow-provider-teradata not available", allow_module_level=True) + +# [START s3_to_teradata_transfer_operator_howto_guide] + + +ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID") +DAG_ID = "example_s3_to_teradata_transfer_operator" +CONN_ID = "teradata_default" + +with DAG( + dag_id=DAG_ID, + start_date=datetime.datetime(2020, 2, 2), + schedule="@once", + catchup=False, + default_args={"conn_id": "teradata_default"}, +) as dag: + # [START s3_to_teradata_transfer_operator_howto_guide_transfer_data_s3_to_teradata_csv] + transfer_data_csv = S3ToTeradataOperator( + task_id="transfer_data_s3_to_teradata_csv", + s3_source_key="/s3/td-usgs-public.s3.amazonaws.com/CSVDATA/09394500/2018/06/", + teradata_table="example_s3_teradata_csv", + aws_conn_id="aws_default", + teradata_conn_id="teradata_default", + trigger_rule="all_done", + ) + # [END s3_to_teradata_transfer_operator_howto_guide_transfer_data_s3_to_teradata_csv] + # [START s3_to_teradata_transfer_operator_howto_guide_read_data_table_csv] + read_data_table_csv = TeradataOperator( + task_id="read_data_table_csv", + conn_id=CONN_ID, + sql=""" + SELECT * from example_s3_teradata_csv; + """, + ) + # [END s3_to_teradata_transfer_operator_howto_guide_read_data_table_csv] + # [START s3_to_teradata_transfer_operator_howto_guide_drop_table_csv] + drop_table_csv = TeradataOperator( + task_id="drop_table_csv", + conn_id=CONN_ID, + sql=""" + DROP TABLE example_s3_teradata_csv; + """, Review Comment: Addressed suggestion in all applicable places. ########## tests/system/providers/teradata/example_s3_to_teradata_transfer.py: ########## @@ -0,0 +1,163 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +""" +Example Airflow DAG to show usage of S3StorageToTeradataOperator. + +The transfer operator moves files in CSV, JSON, and PARQUET formats from S3 +to Teradata tables. In the example Directed Acyclic Graph (DAG) below, it assumes Airflow +Connections with the IDs `teradata_default` and `aws_default` already exist. The DAG creates +tables using data from the S3, reports the number of rows inserted into +the table, and subsequently drops the table. +""" + +from __future__ import annotations + +import datetime +import os + +import pytest + +from airflow import DAG +from airflow.providers.teradata.transfers.s3_to_teradata import S3ToTeradataOperator + +try: + from airflow.providers.teradata.operators.teradata import TeradataOperator +except ImportError: + pytest.skip("Teradata provider apache-airflow-provider-teradata not available", allow_module_level=True) + +# [START s3_to_teradata_transfer_operator_howto_guide] + + +ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID") +DAG_ID = "example_s3_to_teradata_transfer_operator" +CONN_ID = "teradata_default" + +with DAG( + dag_id=DAG_ID, + start_date=datetime.datetime(2020, 2, 2), + schedule="@once", + catchup=False, + default_args={"conn_id": "teradata_default"}, +) as dag: + # [START s3_to_teradata_transfer_operator_howto_guide_transfer_data_s3_to_teradata_csv] + transfer_data_csv = S3ToTeradataOperator( + task_id="transfer_data_s3_to_teradata_csv", + s3_source_key="/s3/td-usgs-public.s3.amazonaws.com/CSVDATA/09394500/2018/06/", + teradata_table="example_s3_teradata_csv", + aws_conn_id="aws_default", + teradata_conn_id="teradata_default", + trigger_rule="all_done", + ) + # [END s3_to_teradata_transfer_operator_howto_guide_transfer_data_s3_to_teradata_csv] + # [START s3_to_teradata_transfer_operator_howto_guide_read_data_table_csv] + read_data_table_csv = TeradataOperator( + task_id="read_data_table_csv", + conn_id=CONN_ID, + sql=""" + SELECT * from example_s3_teradata_csv; + """, + ) + # [END s3_to_teradata_transfer_operator_howto_guide_read_data_table_csv] + # [START s3_to_teradata_transfer_operator_howto_guide_drop_table_csv] + drop_table_csv = TeradataOperator( + task_id="drop_table_csv", + conn_id=CONN_ID, + sql=""" + DROP TABLE example_s3_teradata_csv; + """, + ) + # [END s3_to_teradata_transfer_operator_howto_guide_drop_table_csv] + # [START s3_to_teradata_transfer_operator_howto_guide_transfer_data_s3_to_teradata_json] + transfer_data_json = S3ToTeradataOperator( + task_id="transfer_data_s3_to_teradata_json", + s3_source_key="/s3/td-usgs-public.s3.amazonaws.com/JSONDATA/09394500/2018/06/", + teradata_table="example_s3_teradata_json", + aws_conn_id="aws_default", + teradata_conn_id="teradata_default", + trigger_rule="all_done", + ) + # [END s3_to_teradata_transfer_operator_howto_guide_transfer_data_s3_to_teradata_json] + # [START s3_to_teradata_transfer_operator_howto_guide_read_data_table_json] + read_data_table_json = TeradataOperator( + task_id="read_data_table_json", + conn_id=CONN_ID, + sql=""" + SELECT * from example_s3_teradata_json; + """, Review Comment: Addressed suggestion in all applicable places. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
