Skip to content
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
3 changes: 3 additions & 0 deletions providers/teradata/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ dependencies = [
"ssh" = [
"apache-airflow-providers-ssh"
]
"sqlalchemy" = [
"sqlalchemy>=1.4.49",
]

[dependency-groups]
dev = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
from typing import TYPE_CHECKING, Any

import teradatasql
from sqlalchemy.engine import URL
from teradatasql import TeradataConnection

from airflow.exceptions import AirflowOptionalProviderFeatureException
from airflow.providers.common.sql.hooks.sql import DbApiHook

if TYPE_CHECKING:
Expand All @@ -38,6 +38,18 @@
PARAM_TYPES = {bool, float, int, str}


def _get_sqlalchemy_url():
try:
from sqlalchemy.engine import URL

return URL
except ImportError:
raise AirflowOptionalProviderFeatureException(
"SQLAlchemy is required for this Teradata feature."
"Install it with: pip install 'apache-airflow-providers-teradata[sqlalchemy]'"
)


def _map_param(value):
if value in PARAM_TYPES:
# In this branch, value is a Python type; calling it produces
Expand Down Expand Up @@ -197,12 +209,13 @@ def _get_conn_config_teradatasql(self) -> dict[str, Any]:
return conn_config

@property
def sqlalchemy_url(self) -> URL:
def sqlalchemy_url(self):
"""
Override to return a Sqlalchemy.engine.URL object from the Teradata connection.

:return: the extracted sqlalchemy.engine.URL object.
"""
URL = _get_sqlalchemy_url()
connection = self.get_connection(self.get_conn_id())
# Adding only teradatasqlalchemy supported connection parameters.
# https://pypi.org/project/teradatasqlalchemy/#ConnectionParameters
Expand Down