eladkal commented on code in PR #36953: URL: https://github.com/apache/airflow/pull/36953#discussion_r1463001545
########## airflow/providers/teradata/transfers/teradata_to_teradata.py: ########## @@ -0,0 +1,91 @@ +# +# 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. +from __future__ import annotations + +from typing import TYPE_CHECKING, Sequence + +from airflow.models import BaseOperator +from airflow.providers.teradata.hooks.teradata import TeradataHook + +if TYPE_CHECKING: + from airflow.utils.context import Context + + +class TeradataToTeradataOperator(BaseOperator): + """ + Moves data from Teradata source database to Teradata destination database. + + .. seealso:: + For more information on how to use this operator, take a look at the guide: + :ref:`howto/operator:TeradataToTeradataOperator` + + :param teradata_destination_conn_id: destination Teradata connection. Review Comment: Lets use conventions we already have You can see for example `source_aws_conn_id` & `dest_aws_conn_id` in [S3FileTransformOperator](https://github.com/apache/airflow/blob/9cb2052810a8a4b191e77d804fc79927f046c8bb/airflow/providers/amazon/aws/operators/s3.py#L567) so we need `source_teradata_conn_id` / `dest_teradata_conn_id` ########## airflow/providers/teradata/transfers/teradata_to_teradata.py: ########## @@ -0,0 +1,91 @@ +# +# 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. +from __future__ import annotations + +from typing import TYPE_CHECKING, Sequence + +from airflow.models import BaseOperator +from airflow.providers.teradata.hooks.teradata import TeradataHook + +if TYPE_CHECKING: + from airflow.utils.context import Context + + +class TeradataToTeradataOperator(BaseOperator): + """ + Moves data from Teradata source database to Teradata destination database. + + .. seealso:: + For more information on how to use this operator, take a look at the guide: + :ref:`howto/operator:TeradataToTeradataOperator` + + :param teradata_destination_conn_id: destination Teradata connection. + :param destination_table: destination table to insert rows. + :param teradata_source_conn_id: :ref:`Source Teradata connection <howto/connection:Teradata>`. + :param source_sql: SQL query to execute against the source Teradata database + :param source_sql_params: Parameters to use in sql query. + :param rows_chunk: number of rows per chunk to commit. + """ + + template_fields: Sequence[str] = ( + "source_sql", + "source_sql_params", + ) + template_ext: Sequence[str] = (".sql",) + template_fields_renderers = {"source_sql": "sql", "source_sql_params": "py"} + ui_color = "#e07c24" + + def __init__( + self, + *, + teradata_destination_conn_id: str, + destination_table: str, + teradata_source_conn_id: str, + source_sql: str, + source_sql_params: dict | None = None, + rows_chunk: int = 5000, + **kwargs, + ) -> None: + super().__init__(**kwargs) + if source_sql_params is None: + source_sql_params = {} + self.teradata_destination_conn_id = teradata_destination_conn_id + self.destination_table = destination_table + self.teradata_source_conn_id = teradata_source_conn_id + self.source_sql = source_sql + self.source_sql_params = source_sql_params + self.rows_chunk = rows_chunk + + def _execute(self, src_hook, dest_hook, context) -> None: + with src_hook.get_conn() as src_conn: + cursor = src_conn.cursor() + cursor.execute(self.source_sql, self.source_sql_params) + target_fields = [field[0] for field in cursor.description] + rows_total = 0 + for rows in iter(lambda: cursor.fetchmany(self.rows_chunk), []): + dest_hook.bulk_insert_rows( + self.destination_table, rows, target_fields=target_fields, commit_every=self.rows_chunk + ) + rows_total += len(rows) + self.log.info("Finished data transfer.") + cursor.close() + + def execute(self, context: Context) -> None: + src_hook = TeradataHook(teradata_conn_id=self.teradata_source_conn_id) + dest_hook = TeradataHook(teradata_conn_id=self.teradata_destination_conn_id) + self._execute(src_hook, dest_hook, context) Review Comment: Why do we need this private function? You can mark specific helpers as private but marking the whole execute function as private is not something that we do. If allowed it means that all operators logic is considered internal detail... that doesn't make sense to me. ########## airflow/providers/teradata/example_dags/example_teradata_operator.py: ########## @@ -0,0 +1,132 @@ +# Review Comment: same comment about examples ########## airflow/providers/teradata/example_dags/example_teradata_to_teradata_transfer_operator.py: ########## @@ -0,0 +1,158 @@ +# Review Comment: example dags should be written as system tests and be stored in the system test directory ########## airflow/providers/teradata/transfers/teradata_to_teradata.py: ########## @@ -0,0 +1,91 @@ +# +# 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. +from __future__ import annotations + +from typing import TYPE_CHECKING, Sequence + +from airflow.models import BaseOperator +from airflow.providers.teradata.hooks.teradata import TeradataHook + +if TYPE_CHECKING: + from airflow.utils.context import Context + + +class TeradataToTeradataOperator(BaseOperator): + """ + Moves data from Teradata source database to Teradata destination database. + + .. seealso:: + For more information on how to use this operator, take a look at the guide: + :ref:`howto/operator:TeradataToTeradataOperator` + + :param teradata_destination_conn_id: destination Teradata connection. + :param destination_table: destination table to insert rows. + :param teradata_source_conn_id: :ref:`Source Teradata connection <howto/connection:Teradata>`. + :param source_sql: SQL query to execute against the source Teradata database + :param source_sql_params: Parameters to use in sql query. + :param rows_chunk: number of rows per chunk to commit. + """ + + template_fields: Sequence[str] = ( + "source_sql", Review Comment: Why `source_` ? The query is only on the source there is no other option -- 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]
