Skip to content

Commit

Permalink
Added server side parameters for thrift connection type (#577)
Browse files Browse the repository at this point in the history
* Added server side parameters for thrift connection type

* Adding CHANGELOG Entry

* Minor change: line length and commas.

* Added server side parameters for thrift connection type

* trailing commas

* fix formatting

---------

Co-authored-by: VShkaberda <v.shkaberda@gmail.com>
Co-authored-by: Florian Eiden <florian.eiden@fleid.fr>
Co-authored-by: colin-rogers-dbt <111200756+colin-rogers-dbt@users.noreply.github.com>
Co-authored-by: Colin <colin.rogers@dbtlabs.com>
  • Loading branch information
5 people authored Aug 16, 2023
1 parent 62e87ea commit cb39fb1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Features-20221229-200956.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Features
body: Support server side parameters in thrift connection
time: 2022-12-29T20:09:56.457776+02:00
custom:
Author: ' hanna-liashchuk'
Issue: "387"
PR: "577"
6 changes: 5 additions & 1 deletion dbt/adapters/spark/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,10 @@ def open(cls, connection: Connection) -> Connection:
kerberos_service_name=creds.kerberos_service_name,
password=creds.password,
)
conn = hive.connect(thrift_transport=transport)
conn = hive.connect(
thrift_transport=transport,
configuration=creds.server_side_parameters,
)
else:
conn = hive.connect(
host=creds.host,
Expand All @@ -448,6 +451,7 @@ def open(cls, connection: Connection) -> Connection:
auth=creds.auth,
kerberos_service_name=creds.kerberos_service_name,
password=creds.password,
configuration=creds.server_side_parameters,
) # noqa
handle = PyhiveConnectionWrapper(conn)
elif creds.method == SparkConnectionMethod.ODBC:
Expand Down
14 changes: 11 additions & 3 deletions tests/unit/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,16 @@ def test_thrift_connection(self):
config = self._get_target_thrift(self.project_cfg)
adapter = SparkAdapter(config)

def hive_thrift_connect(host, port, username, auth, kerberos_service_name, password):
def hive_thrift_connect(
host, port, username, auth, kerberos_service_name, password, configuration
):
self.assertEqual(host, "myorg.sparkhost.com")
self.assertEqual(port, 10001)
self.assertEqual(username, "dbt")
self.assertIsNone(auth)
self.assertIsNone(kerberos_service_name)
self.assertIsNone(password)
self.assertDictEqual(configuration, {})

with mock.patch.object(hive, "connect", new=hive_thrift_connect):
connection = adapter.acquire_connection("dummy")
Expand All @@ -194,11 +197,12 @@ def test_thrift_ssl_connection(self):
config = self._get_target_use_ssl_thrift(self.project_cfg)
adapter = SparkAdapter(config)

def hive_thrift_connect(thrift_transport):
def hive_thrift_connect(thrift_transport, configuration):
self.assertIsNotNone(thrift_transport)
transport = thrift_transport._trans
self.assertEqual(transport.host, "myorg.sparkhost.com")
self.assertEqual(transport.port, 10001)
self.assertDictEqual(configuration, {})

with mock.patch.object(hive, "connect", new=hive_thrift_connect):
connection = adapter.acquire_connection("dummy")
Expand All @@ -213,13 +217,16 @@ def test_thrift_connection_kerberos(self):
config = self._get_target_thrift_kerberos(self.project_cfg)
adapter = SparkAdapter(config)

def hive_thrift_connect(host, port, username, auth, kerberos_service_name, password):
def hive_thrift_connect(
host, port, username, auth, kerberos_service_name, password, configuration
):
self.assertEqual(host, "myorg.sparkhost.com")
self.assertEqual(port, 10001)
self.assertEqual(username, "dbt")
self.assertEqual(auth, "KERBEROS")
self.assertEqual(kerberos_service_name, "hive")
self.assertIsNone(password)
self.assertDictEqual(configuration, {})

with mock.patch.object(hive, "connect", new=hive_thrift_connect):
connection = adapter.acquire_connection("dummy")
Expand Down Expand Up @@ -710,6 +717,7 @@ def test_parse_columns_from_information_with_table_type_and_parquet_provider(sel
config = self._get_target_http(self.project_cfg)
columns = SparkAdapter(config).parse_columns_from_information(relation)
self.assertEqual(len(columns), 4)

self.assertEqual(
columns[2].to_column_dict(omit_none=False),
{
Expand Down

0 comments on commit cb39fb1

Please sign in to comment.