Skip to content

Commit

Permalink
Add get_identifier to hive source in metadata ingestion
Browse files Browse the repository at this point in the history
    The hive source currently does not include the catalog name
    in the schema name. This is due to the SQLAlchemy
    reflection that pyhive performs. Without the catalog
    name, multiple hive sources could have collisions
    with the urns generated. This function will add
    the database name where applicable and solve this problem.
  • Loading branch information
zack3241 committed Jun 8, 2021
1 parent 2f7b4f9 commit c0db89c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions metadata-ingestion/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def get_long_description():
"ldap",
"looker",
"glue",
"hive",
"datahub-kafka",
"datahub-rest",
# airflow is added below
Expand Down
6 changes: 6 additions & 0 deletions metadata-ingestion/src/datahub/ingestion/source/hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class HiveConfig(BasicSQLAlchemyConfig):
# defaults
scheme = "hive"

def get_identifier(self, schema: str, table: str) -> str:
regular = f"{schema}.{table}"
if self.database:
return f"{self.database}.{regular}"
return regular


class HiveSource(SQLAlchemySource):
def __init__(self, config, ctx):
Expand Down
23 changes: 23 additions & 0 deletions metadata-ingestion/tests/unit/test_hive_source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import unittest

from datahub.ingestion.source.hive import HiveConfig


class HiveSinkTest(unittest.TestCase):
def test_hive_configuration_get_indentifier_with_database(self):
test_db_name = "test_database"
test_schema_name = "test_schema"
test_table_name = "test_table"
config_dict = {
"username": "test",
"password": "test",
"host_port": "test:80",
"database": test_db_name,
"scheme": "hive+https",
}
hive_config = HiveConfig.parse_obj(config_dict)
expected_output = f"{test_db_name}.{test_schema_name}.{test_table_name}"
output = hive_config.get_identifier(
schema=test_schema_name, table=test_table_name
)
assert output == expected_output

0 comments on commit c0db89c

Please sign in to comment.