Skip to content
Closed
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
5 changes: 4 additions & 1 deletion airflow/providers/apache/druid/hooks/druid.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ def get_conn_url(self, ingestion_type: IngestionType = IngestionType.BATCH) -> s
"""Get Druid connection url."""
host = self.conn.host
port = self.conn.port
conn_type = self.conn.conn_type or "http"
if self.conn.schema:
conn_type = self.conn.schema
else:
conn_type = self.conn.conn_type or "http"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we define "http" as a constant that denoted the default connection type?

if ingestion_type == IngestionType.BATCH:
endpoint = self.conn.extra_dejson.get("endpoint", "")
else:
Expand Down
39 changes: 34 additions & 5 deletions tests/providers/apache/druid/hooks/test_druid.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ class TestDRuidhook(DruidHook):
self.is_sql_based_ingestion = False

def get_conn_url(self, ingestion_type: IngestionType = IngestionType.BATCH):
if self.conn.schema:
conn_type = self.conn.schema
else:
conn_type = "http"

if ingestion_type == IngestionType.MSQ:
return "http://druid-overlord:8081/druid/v2/sql/task"
return "http://druid-overlord:8081/druid/indexer/v1/task"
return f"{conn_type}//druid-overlord:8081/druid/v2/sql/task"
return f"{conn_type}://druid-overlord:8081/druid/indexer/v1/task"

self.db_hook = TestDRuidhook()

Expand Down Expand Up @@ -254,7 +259,7 @@ def get_conn_url(self, ingestion_type: IngestionType = IngestionType.BATCH):
def test_conn_property(self, mock_get_connection):
get_conn_value = MagicMock()
get_conn_value.host = "test_host"
get_conn_value.conn_type = "https"
get_conn_value.conn_type = "http"
get_conn_value.port = "1"
get_conn_value.extra_dejson = {"endpoint": "ingest"}
mock_get_connection.return_value = get_conn_value
Expand All @@ -265,8 +270,20 @@ def test_conn_property(self, mock_get_connection):
def test_get_conn_url(self, mock_get_connection):
get_conn_value = MagicMock()
get_conn_value.host = "test_host"
get_conn_value.conn_type = "https"
get_conn_value.conn_type = "http"
get_conn_value.port = "1"
get_conn_value.extra_dejson = {"endpoint": "ingest"}
mock_get_connection.return_value = get_conn_value
hook = DruidHook(timeout=1, max_ingestion_time=5)
assert hook.get_conn_url() == "http://test_host:1/ingest"

@patch("airflow.providers.apache.druid.hooks.druid.DruidHook.get_connection")
def test_get_conn_url_with_schema(self, mock_get_connection):
get_conn_value = MagicMock()
get_conn_value.host = "test_host"
get_conn_value.conn_type = "http"
get_conn_value.port = "1"
get_conn_value.schema = "https"
get_conn_value.extra_dejson = {"endpoint": "ingest"}
mock_get_connection.return_value = get_conn_value
hook = DruidHook(timeout=1, max_ingestion_time=5)
Expand All @@ -276,8 +293,20 @@ def test_get_conn_url(self, mock_get_connection):
def test_get_conn_url_with_ingestion_type(self, mock_get_connection):
get_conn_value = MagicMock()
get_conn_value.host = "test_host"
get_conn_value.conn_type = "https"
get_conn_value.conn_type = "http"
get_conn_value.port = "1"
get_conn_value.extra_dejson = {"endpoint": "ingest", "msq_endpoint": "sql_ingest"}
mock_get_connection.return_value = get_conn_value
hook = DruidHook(timeout=1, max_ingestion_time=5)
assert hook.get_conn_url(IngestionType.MSQ) == "http://test_host:1/sql_ingest"

@patch("airflow.providers.apache.druid.hooks.druid.DruidHook.get_connection")
def test_get_conn_url_with_ingestion_type_and_schema(self, mock_get_connection):
get_conn_value = MagicMock()
get_conn_value.host = "test_host"
get_conn_value.conn_type = "http"
get_conn_value.port = "1"
get_conn_value.schema = "https"
get_conn_value.extra_dejson = {"endpoint": "ingest", "msq_endpoint": "sql_ingest"}
mock_get_connection.return_value = get_conn_value
hook = DruidHook(timeout=1, max_ingestion_time=5)
Expand Down