From 673f7ffbcbae3c7f66ff504eeba612a2d8262398 Mon Sep 17 00:00:00 2001 From: whitepowder Date: Mon, 25 Aug 2025 22:12:20 +0600 Subject: [PATCH 1/2] add DbtTrinoHook and tests --- airflow_dbt_python/hooks/target.py | 35 ++++++++++++++++ tests/hooks/test_trino.py | 65 ++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 tests/hooks/test_trino.py diff --git a/airflow_dbt_python/hooks/target.py b/airflow_dbt_python/hooks/target.py index ac74f55..0a8d581 100644 --- a/airflow_dbt_python/hooks/target.py +++ b/airflow_dbt_python/hooks/target.py @@ -492,3 +492,38 @@ class DbtSparkHook(DbtConnectionHook): ), ] conn_extra_params = [] + + +class DbtTrinoHook(DbtConnectionHook): + """A hook to interact with dbt using a Trino connection.""" + + conn_type = "trino" + hook_name = "dbt Trino Hook" + airflow_conn_types = (conn_type,) + + conn_params = [ + "host", + DbtConnectionParam("schema", default="public"), + DbtConnectionParam("login", "user"), + "password", + DbtConnectionParam("port", default=443), + ] + + conn_extra_params = [ + DbtConnectionParam("type", default="trino"), + DbtConnectionParam("method", default="none"), + DbtConnectionParam("http_scheme", default="https"), + DbtConnectionParam("verify", default=True), + DbtConnectionParam("database", "catalog", "hive"), + "catalog", + "host", + "port", + DbtConnectionParam("user", "user"), + "password", + "schema", + "session_properties", + "http_headers", + "role", + "client_tags", + "source", + ] diff --git a/tests/hooks/test_trino.py b/tests/hooks/test_trino.py new file mode 100644 index 0000000..c0746a0 --- /dev/null +++ b/tests/hooks/test_trino.py @@ -0,0 +1,65 @@ +"""Tests for the DbtTrinoHook.""" + +from airflow.models.connection import Connection + +from airflow_dbt_python.hooks.target import DbtConnectionHook, DbtTrinoHook + + +def test_trino_registration(): + """Ensure that a Trino connection is mapped to a valid dbt profile dict.""" + conn = Connection( + conn_id="my_trino", + conn_type="trino", + extra=""" + { + "type": "trino", + "method": "ldap", + "user": "user", + "password": "pass", + "host": "trino-etl.example", + "port": 443, + "http_scheme": "https", + "database": "ads_dwh_hdfs", + "schema": "ads_platform_dwh", + "verify": false + } + """, + ) + + trino_hook = DbtTrinoHook(conn=conn) + details = trino_hook.get_dbt_details_from_connection(conn) + + assert details["type"] == "trino" + assert details["method"] == "ldap" + assert details["host"] == "trino-etl.example" + assert details["port"] == 443 + assert details["user"] == "user" + assert details["password"] == "pass" + assert details["schema"] == "ads_platform_dwh" + assert details["catalog"] == "ads_dwh_hdfs" + assert details["verify"] is False + + +def test_trino_catalog_overrides_database(): + """Ensure that explicit catalog overrides database → catalog fallback.""" + conn = Connection( + conn_id="my_trino_catalog", + conn_type="trino", + extra=""" + { + "type": "trino", + "user": "u", + "password": "p", + "host": "h", + "port": 8443, + "database": "fallback_db", + "catalog": "explicit_catalog", + "schema": "s" + } + """, + ) + + trino_hook = DbtTrinoHook(conn=conn) + details = trino_hook.get_dbt_details_from_connection(conn) + + assert details["catalog"] == "explicit_catalog" From ae4d95bb5b9eb2cc6a2436bcaa132b353ff5a262 Mon Sep 17 00:00:00 2001 From: whitepowder Date: Mon, 25 Aug 2025 22:47:35 +0600 Subject: [PATCH 2/2] add DbtTrinoHook and tests --- tests/hooks/test_trino.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/hooks/test_trino.py b/tests/hooks/test_trino.py index c0746a0..2bdb3d0 100644 --- a/tests/hooks/test_trino.py +++ b/tests/hooks/test_trino.py @@ -16,11 +16,11 @@ def test_trino_registration(): "method": "ldap", "user": "user", "password": "pass", - "host": "trino-etl.example", + "host": "trino.example", "port": 443, "http_scheme": "https", - "database": "ads_dwh_hdfs", - "schema": "ads_platform_dwh", + "database": "example", + "schema": "example", "verify": false } """, @@ -31,12 +31,12 @@ def test_trino_registration(): assert details["type"] == "trino" assert details["method"] == "ldap" - assert details["host"] == "trino-etl.example" + assert details["host"] == "trino.example" assert details["port"] == 443 assert details["user"] == "user" assert details["password"] == "pass" - assert details["schema"] == "ads_platform_dwh" - assert details["catalog"] == "ads_dwh_hdfs" + assert details["schema"] == "example" + assert details["catalog"] == "example" assert details["verify"] is False