Skip to content

Commit

Permalink
Addressed issue with version
Browse files Browse the repository at this point in the history
  • Loading branch information
FastLee committed Dec 5, 2024
1 parent 6fae8ac commit debe61a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/databricks/labs/ucx/hive_metastore/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ def __init__(
self._enable_hms_federation = enable_hms_federation
self._installation = installation

# Supported databases and version for HMS Federation
supported_db_vers: ClassVar[dict[str, list[str]]] = {
"mysql": ["2.3.0", "0.13"],
"mysql": ["2.3", "0.13"],
}

def create_from_cli(self, prompts: Prompts):
Expand All @@ -75,7 +76,7 @@ def create_from_cli(self, prompts: Prompts):
try:
ext_hms = self._get_ext_hms()
except ValueError:
logger.info('Failed to get external Hive Metastore connection information')
logger.info('Failed to retrieve external Hive Metastore connection information')

if ext_hms and prompts.confirm(
f'A supported external Hive Metastore connection was identified: {ext_hms.db_type}. Use this connection?'
Expand All @@ -95,8 +96,13 @@ def _get_ext_hms(self) -> ExtHms:
if not jdbc_url:
raise ValueError('JDBC URL not found')
version = self._get_value_from_config_key(spark_config, 'spark.sql.hive.metastore.version')
# extract major version from version using regex
if not version:
raise ValueError('Hive Metastore version not found')
major_version = re.match(r'(\d+\.\d+)', version)
if not major_version:
raise ValueError(f'Invalid Hive Metastore version: {version}')
version = major_version.group(1)
ext_hms = replace(self._split_jdbc_url(jdbc_url), version=version)
supported_versions = self.supported_db_vers.get(ext_hms.db_type)
if not supported_versions:
Expand Down Expand Up @@ -166,7 +172,7 @@ def _get_or_create_int_connection(self, name: str) -> ConnectionInfo:

def _get_or_create_ext_connection(self, name: str, ext_hms: ExtHms) -> ConnectionInfo:
options: dict[str, str] = {
"builtin": "false",
# TODO: Fix once the FEDERATION end point is fixed. Include "builtin": "false" in options
"database": ext_hms.database,
"db_type": ext_hms.db_type,
"host": ext_hms.host,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/hive_metastore/test_federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_create_federated_catalog_ext(mock_installation):
'password': 'bar',
'port': '3306',
'user': 'foo',
'version': '2.3.0',
'version': '2.3',
},
)
workspace_client.catalogs.create.assert_called_with(
Expand Down

0 comments on commit debe61a

Please sign in to comment.