From 41eca7bc58377656ea3feec33ed94c27a3c28f9d Mon Sep 17 00:00:00 2001 From: Lucas Mendes Mota da Fonseca Date: Wed, 27 Jan 2021 10:49:40 -0300 Subject: [PATCH] [DAE-63] Remove method returning for create_database_if_not_exists (#39) * Remove method returning * Update docs --- docs/source/getstarted.md | 3 ++- hive_metastore_client/hive_metastore_client.py | 5 ++--- .../test_hive_metastore_client.py | 10 ++-------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/docs/source/getstarted.md b/docs/source/getstarted.md index de70c24..7e1cd5d 100644 --- a/docs/source/getstarted.md +++ b/docs/source/getstarted.md @@ -36,4 +36,5 @@ Beyond the default methods, this library also implements the methods below in the [`HiveMetastoreClient`](https://github.com/quintoandar/hive-metastore-client/blob/main/hive_metastore_client/hive_metastore_client.py) class: - [`add_columns_to_table`](https://hive-metastore-client.readthedocs.io/en/latest/hive_metastore_client.html#hive_metastore_client.hive_metastore_client.HiveMetastoreClient.add_columns_to_table) -- [`add_partitions_to_table`](https://hive-metastore-client.readthedocs.io/en/latest/hive_metastore_client.html#hive_metastore_client.hive_metastore_client.HiveMetastoreClient.add_columns_to_table) \ No newline at end of file +- [`add_partitions_to_table`](https://hive-metastore-client.readthedocs.io/en/latest/hive_metastore_client.html#hive_metastore_client.hive_metastore_client.HiveMetastoreClient.add_partitions_to_table) +- [`create_database_if_not_exists`](https://hive-metastore-client.readthedocs.io/en/latest/hive_metastore_client.html#hive_metastore_client.hive_metastore_client.HiveMetastoreClient.create_database_if_not_exists) \ No newline at end of file diff --git a/hive_metastore_client/hive_metastore_client.py b/hive_metastore_client/hive_metastore_client.py index aa39326..ee4e897 100644 --- a/hive_metastore_client/hive_metastore_client.py +++ b/hive_metastore_client/hive_metastore_client.py @@ -133,7 +133,7 @@ def add_partitions_to_table( self.add_partitions(partition_list_with_correct_location) - def create_database_if_not_exists(self, database: Database) -> bool: + def create_database_if_not_exists(self, database: Database) -> None: """ Creates the table in Hive Metastore if it does not exist. @@ -145,9 +145,8 @@ def create_database_if_not_exists(self, database: Database) -> bool: """ try: self.create_database(database) - return True except AlreadyExistsException: - return False + pass @staticmethod def _format_partitions_location( diff --git a/tests/unit/hive_metastore_client/test_hive_metastore_client.py b/tests/unit/hive_metastore_client/test_hive_metastore_client.py index ca6eded..ab96001 100644 --- a/tests/unit/hive_metastore_client/test_hive_metastore_client.py +++ b/tests/unit/hive_metastore_client/test_hive_metastore_client.py @@ -219,12 +219,9 @@ def test_create_database_if_not_exists_with_nonexistent_database( mocked_database_obj = Mock() # act - return_value = hive_metastore_client.create_database_if_not_exists( - mocked_database_obj - ) + hive_metastore_client.create_database_if_not_exists(mocked_database_obj) # assert - assert return_value mocked_create_database.assert_called_once_with(mocked_database_obj) @mock.patch.object(HiveMetastoreClient, "create_database") @@ -236,10 +233,7 @@ def test_create_database_if_not_exists_with_existent_database( mocked_create_database.side_effect = AlreadyExistsException() # act - return_value = hive_metastore_client.create_database_if_not_exists( - mocked_database_obj - ) + hive_metastore_client.create_database_if_not_exists(mocked_database_obj) # assert - assert not return_value mocked_create_database.assert_called_once_with(mocked_database_obj)