Skip to content
Open
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 @@ -184,15 +184,30 @@ def _get_sql_endpoint_by_name(self, endpoint_name) -> dict[str, Any]:
else:
return endpoint

def _resolve_http_path(self, allow_endpoint_lookup: bool = True) -> str | None:
"""
Resolve http_path from explicit arg, connection extra, or endpoint name.

:param allow_endpoint_lookup: If True, may call API to resolve sql_endpoint_name.
Set False for offline-safe paths like sqlalchemy_url.
:return: resolved http_path or None if not found.
"""
if self._http_path:
return self._http_path
if "http_path" in self.databricks_conn.extra_dejson:
self._http_path = self.databricks_conn.extra_dejson["http_path"]
return self._http_path
if allow_endpoint_lookup and self._sql_endpoint_name:
endpoint = self._get_sql_endpoint_by_name(self._sql_endpoint_name)
self._http_path = endpoint["odbc_params"]["path"]
return self._http_path
return self._http_path

def get_conn(self) -> AirflowConnection:
"""Return a Databricks SQL connection object."""
if not self._http_path:
if self._sql_endpoint_name:
endpoint = self._get_sql_endpoint_by_name(self._sql_endpoint_name)
self._http_path = endpoint["odbc_params"]["path"]
elif "http_path" in self.databricks_conn.extra_dejson:
self._http_path = self.databricks_conn.extra_dejson["http_path"]
else:
self._http_path = self._resolve_http_path(allow_endpoint_lookup=True)
if not self._http_path:
raise AirflowException(
"http_path should be provided either explicitly, "
"or in extra parameter of Databricks connection, "
Expand Down Expand Up @@ -254,8 +269,10 @@ def sqlalchemy_url(self) -> URL:
"Install it with: pip install 'apache-airflow-providers-databricks[sqlalchemy]'"
)

http_path = self._resolve_http_path(allow_endpoint_lookup=False)

url_query = {
"http_path": self._http_path,
"http_path": http_path,
"catalog": self.catalog,
"schema": self.schema,
}
Expand Down