Skip to content

Commit 442830c

Browse files
fix(hive): pass drivername to metastore helper and fix describe test mocks (#26712)
1 parent 120a1a6 commit 442830c

2 files changed

Lines changed: 10 additions & 33 deletions

File tree

ingestion/src/metadata/ingestion/source/database/hive/metadata.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,8 @@ def _build_metastore_partition_query(self, drivername: str) -> str:
183183
)
184184

185185
def _get_partition_keys_from_metastore(
186-
self, table_name: str, schema_name: str
186+
self, table_name: str, schema_name: str, drivername: str
187187
) -> List[str]:
188-
drivername = getattr(getattr(self.engine, "url", None), "drivername", "")
189188
query = self._build_metastore_partition_query(drivername)
190189
result = self.connection.execute(
191190
text(query),
@@ -235,7 +234,7 @@ def get_table_partition_details( # pylint: disable=unused-argument
235234
drivername = getattr(getattr(self.engine, "url", None), "drivername", "")
236235
if drivername in {"hive+mysql", "hive+postgres"}:
237236
partition_keys = self._get_partition_keys_from_metastore(
238-
table_name, schema_name
237+
table_name, schema_name, drivername
239238
)
240239
else:
241240
partition_keys = self._get_partition_keys_from_describe(

ingestion/tests/unit/topology/database/test_hive.py

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -566,26 +566,15 @@ def test_get_table_partition_details_non_partitioned_metastore(self):
566566
self.assertIsNone(partition)
567567

568568
def test_get_table_partition_details_non_partitioned_describe(self):
569-
class ConnectionContextManager:
570-
def __init__(self, connection):
571-
self._connection = connection
572-
573-
def __enter__(self):
574-
return self._connection
575-
576-
def __exit__(self, exc_type, exc, tb):
577-
return False
578-
569+
self.hive.engine = types.SimpleNamespace(
570+
url=types.SimpleNamespace(drivername="hive")
571+
)
579572
mock_connection = Mock()
580573
mock_connection.execute.return_value = [
581574
("id", "int", None),
582575
("name", "string", None),
583576
]
584-
585-
self.hive.engine = types.SimpleNamespace(
586-
url=types.SimpleNamespace(drivername="hive"),
587-
connect=lambda: ConnectionContextManager(mock_connection),
588-
)
577+
self.hive._connection_map[self.thread_id] = mock_connection
589578

590579
is_partitioned, partition = self.hive.get_table_partition_details(
591580
table_name="non_partitioned", schema_name="sample_schema", inspector=Mock()
@@ -595,16 +584,9 @@ def __exit__(self, exc_type, exc, tb):
595584
self.assertIsNone(partition)
596585

597586
def test_get_table_partition_details_from_describe_formatted(self):
598-
class ConnectionContextManager:
599-
def __init__(self, connection):
600-
self._connection = connection
601-
602-
def __enter__(self):
603-
return self._connection
604-
605-
def __exit__(self, exc_type, exc, tb):
606-
return False
607-
587+
self.hive.engine = types.SimpleNamespace(
588+
url=types.SimpleNamespace(drivername="hive")
589+
)
608590
mock_connection = Mock()
609591
mock_connection.execute.return_value = [
610592
("id", "int", None),
@@ -616,11 +598,7 @@ def __exit__(self, exc_type, exc, tb):
616598
("# Detailed Table Information", None, None),
617599
("Database:", "default", None),
618600
]
619-
620-
self.hive.engine = types.SimpleNamespace(
621-
url=types.SimpleNamespace(drivername="hive"),
622-
connect=lambda: ConnectionContextManager(mock_connection),
623-
)
601+
self.hive._connection_map[self.thread_id] = mock_connection
624602

625603
is_partitioned, partition = self.hive.get_table_partition_details(
626604
table_name="sample_table", schema_name="sample_schema", inspector=Mock()

0 commit comments

Comments
 (0)