Changed ometa_service_name to database_service_name (#6454)

This commit is contained in:
Teddy 2022-08-01 07:41:46 +02:00 committed by GitHub
parent 62877c2e5d
commit 7c70adc33e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 3 deletions

View File

@ -16,6 +16,7 @@ This subpackage needs to be used in Great Expectations
checkpoints actions. checkpoints actions.
""" """
import warnings
from typing import Dict, Optional, Union from typing import Dict, Optional, Union
from great_expectations.checkpoint.actions import ValidationAction from great_expectations.checkpoint.actions import ValidationAction
@ -68,13 +69,29 @@ class OpenMetadataValidationAction(ValidationAction):
data_context: DataContext, data_context: DataContext,
*, *,
config_file_path: str = None, config_file_path: str = None,
database_service_name: Optional[str] = None,
ometa_service_name: Optional[str] = None, ometa_service_name: Optional[str] = None,
): ):
super().__init__(data_context) super().__init__(data_context)
self.ometa_service_name = ometa_service_name self._ometa_service_name = (
ometa_service_name # will be deprecated in future release
)
self._database_service_name = database_service_name
self.config_file_path = config_file_path self.config_file_path = config_file_path
self.ometa_conn = self._create_ometa_connection() self.ometa_conn = self._create_ometa_connection()
@property
def database_service_name(self):
"""Handle depracation warning"""
if self._ometa_service_name:
warnings.warn(
"`ometa_service_name` will be deperacted in future releases. Use `database_service_name` instead",
DeprecationWarning,
)
return self._ometa_service_name
return self._database_service_name
# pylint: disable=arguments-differ,unused-argument # pylint: disable=arguments-differ,unused-argument
def _run( def _run(
self, self,
@ -152,10 +169,10 @@ class OpenMetadataValidationAction(ValidationAction):
ValueError: if 2 entities with the same ValueError: if 2 entities with the same
`database`.`schema`.`table` are found `database`.`schema`.`table` are found
""" """
if self.ometa_service_name: if self.database_service_name:
return self.ometa_conn.get_by_name( return self.ometa_conn.get_by_name(
entity=Table, entity=Table,
fqn=f"{self.ometa_service_name}.{database}.{schema_name}.{table_name}", fqn=f"{self.database_service_name}.{database}.{schema_name}.{table_name}",
) )
table_entity = [ table_entity = [

View File

@ -15,6 +15,7 @@ Test suite for the action module implementation
import os import os
from unittest import mock from unittest import mock
import pytest
from jinja2 import Environment from jinja2 import Environment
from pytest import mark from pytest import mark
@ -41,6 +42,27 @@ def test_get_table_entity(input, expected, mocked_ometa, mocked_ge_data_context)
assert res._type == expected assert res._type == expected
@mark.parametrize(
"input,expected",
[
(None, "list_entities"),
("service_name", "get_by_name"),
],
)
def test_get_table_entity_database_service_name(
input, expected, mocked_ometa, mocked_ge_data_context
):
"""Test get table entity"""
ometa_validation = OpenMetadataValidationAction(
data_context=mocked_ge_data_context,
config_file_path="my/config/path",
database_service_name=input,
)
res = ometa_validation._get_table_entity("database", "schema", "table")
assert res._type == expected
def test_create_jinja_environment(fixture_jinja_environment): def test_create_jinja_environment(fixture_jinja_environment):
"""Test create jinja environment""" """Test create jinja environment"""
assert isinstance(fixture_jinja_environment, Environment) assert isinstance(fixture_jinja_environment, Environment)