Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@

from collections.abc import Iterable
from typing import TYPE_CHECKING, Any, NoReturn

from sqlalchemy import create_engine
from airflow.exceptions import AirflowOptionalProviderFeatureException
try:
from sqlalchemy import create_engine
except ImportError:
create_engine = None

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

Expand Down Expand Up @@ -52,6 +55,11 @@ class DrillHook(DbApiHook):
def get_conn(self) -> PoolProxiedConnection:
"""Establish a connection to Drillbit."""
conn_md = self.get_connection(self.get_conn_id())

if create_engine is None:

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

raise AirflowOptionalProviderFeatureException("The 'sqlalchemy' library is required to use this hook.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
raise AirflowOptionalProviderFeatureException("The 'sqlalchemy' library is required to use this hook.")
raise AirflowOptionalProviderFeatureException(
"sqlalchemy is required for SQL filter clause generation. "
"Install it with: pip install 'apache-airflow-providers-drill[sqlalchemy]'"
)


creds = f"{conn_md.login}:{conn_md.password}@" if conn_md.login else ""
database_url = (
f"{conn_md.extra_dejson.get('dialect_driver', 'drill+sadrill')}://{creds}"
Expand Down
Loading