-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Updates to Teradata Provider #39217
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
Merged
Merged
Updates to Teradata Provider #39217
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1596bee
Updates to Teradata Provider with release 2.2.0
satish-chinthanippu 73ca455
PR initial review comments addressed (#36)
satish-chinthanippu c28ac1a
Merge branch 'apache:main' into main
satish-chinthanippu ba0e5d9
Generated provider dependenices
satish-chinthanippu 0a9c4af
pre-commit format applied
satish-chinthanippu f815fef
Merge branch 'apache:main' into main
satish-chinthanippu 1747e64
Addressed PR review comments
satish-chinthanippu 4baf9ab
unit tests failure issue fixed
satish-chinthanippu dd2dce4
Address PR comments (#42)
satish-chinthanippu 1b1e1cc
Merge branch 'main' into main
satish-chinthanippu c235f87
Merge branch 'main' into main
satish-chinthanippu 5e6fa8d
Merge branch 'main' into main
satish-chinthanippu b51811b
Merge branch 'main' into main
satish-chinthanippu 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
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
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
103 changes: 103 additions & 0 deletions
103
airflow/providers/teradata/transfers/azure_blob_to_teradata.py
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 |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| # | ||
| # 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 textwrap import dedent | ||
| from typing import TYPE_CHECKING, Sequence | ||
|
|
||
| from airflow.models import BaseOperator | ||
|
|
||
| try: | ||
| from airflow.providers.microsoft.azure.hooks.wasb import WasbHook | ||
| except ModuleNotFoundError as e: | ||
| from airflow.exceptions import AirflowOptionalProviderFeatureException | ||
|
|
||
| raise AirflowOptionalProviderFeatureException(e) | ||
|
|
||
| from airflow.providers.teradata.hooks.teradata import TeradataHook | ||
|
|
||
| if TYPE_CHECKING: | ||
| from airflow.utils.context import Context | ||
|
|
||
|
|
||
| class AzureBlobStorageToTeradataOperator(BaseOperator): | ||
| """ | ||
|
|
||
| Loads CSV, JSON and Parquet format data from Azure Blob Storage to Teradata. | ||
|
|
||
| .. seealso:: | ||
| For more information on how to use this operator, take a look at the guide: | ||
| :ref:`howto/operator:AzureBlobStorageToTeradataOperator` | ||
|
|
||
| :param blob_source_key: The URI format specifying the location of the Azure blob object store.(templated) | ||
| The URI format is `/az/YOUR-STORAGE-ACCOUNT.blob.core.windows.net/YOUR-CONTAINER/YOUR-BLOB-LOCATION`. | ||
| Refer to | ||
| https://docs.teradata.com/search/documents?query=native+object+store&sort=last_update&virtual-field=title_only&content-lang=en-US | ||
| :param azure_conn_id: The Airflow WASB connection used for azure blob credentials. | ||
| :param teradata_table: The name of the teradata table to which the data is transferred.(templated) | ||
| :param teradata_conn_id: The connection ID used to connect to Teradata | ||
| :ref:`Teradata connection <howto/connection:Teradata>` | ||
|
|
||
| Note that ``blob_source_key`` and ``teradata_table`` are | ||
| templated, so you can use variables in them if you wish. | ||
| """ | ||
|
|
||
| template_fields: Sequence[str] = ("blob_source_key", "teradata_table") | ||
| ui_color = "#e07c24" | ||
|
|
||
| def __init__( | ||
| self, | ||
| *, | ||
| blob_source_key: str, | ||
| azure_conn_id: str = "azure_default", | ||
| teradata_table: str, | ||
| teradata_conn_id: str = "teradata_default", | ||
| **kwargs, | ||
| ) -> None: | ||
| super().__init__(**kwargs) | ||
| self.blob_source_key = blob_source_key | ||
| self.azure_conn_id = azure_conn_id | ||
| self.teradata_table = teradata_table | ||
| self.teradata_conn_id = teradata_conn_id | ||
|
|
||
| def execute(self, context: Context) -> None: | ||
| self.log.info( | ||
| "transferring data from %s to teradata table %s...", self.blob_source_key, self.teradata_table | ||
| ) | ||
| azure_hook = WasbHook(wasb_conn_id=self.azure_conn_id) | ||
| conn = azure_hook.get_connection(self.azure_conn_id) | ||
| # Obtaining the Azure client ID and Azure secret in order to access a specified Blob container | ||
| access_id = conn.login if conn.login is not None else "" | ||
| access_secret = conn.password if conn.password is not None else "" | ||
| teradata_hook = TeradataHook(teradata_conn_id=self.teradata_conn_id) | ||
| sql = dedent(f""" | ||
| CREATE MULTISET TABLE {self.teradata_table} AS | ||
| ( | ||
| SELECT * FROM ( | ||
| LOCATION = '{self.blob_source_key}' | ||
| ACCESS_ID= '{access_id}' | ||
| ACCESS_KEY= '{access_secret}' | ||
potiuk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) AS d | ||
| ) WITH DATA | ||
| """).rstrip() | ||
| try: | ||
| teradata_hook.run(sql, True) | ||
| except Exception as ex: | ||
| self.log.error(str(ex)) | ||
| raise | ||
| self.log.info("The transfer of data from Azure Blob to Teradata was successful") | ||
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.
Uh oh!
There was an error while loading. Please reload this page.