-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DAE-63] Handling exception when adding duplicate partitions #37
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4f58524
Handling exception when adding duplicate partitions to prevent failurβ¦
30ca6c2
apply lint
a2ba8c8
Add validation for empty list
00338f9
Add log in exceptions
90f7b99
Remove logs and rename method to hive_client.add_partitions_if_not_exβ¦
9b5b8bc
Update docs
d247abe
Fix doc link and update docstring
74f975a
Merge branch 'main' into lucasmmota/dae-63-handle-exception
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from unittest import mock | ||
from unittest.mock import Mock | ||
from unittest.mock import Mock, ANY | ||
|
||
import pytest | ||
from pytest import raises | ||
|
||
from hive_metastore_client import HiveMetastoreClient | ||
from thrift_files.libraries.thrift_hive_metastore_client.ThriftHiveMetastore import ( | ||
|
@@ -164,16 +165,53 @@ def test_add_partitions_to_table( | |
# arrange | ||
db_name = "database_name" | ||
table_name = "table_name" | ||
formatted_partitions_location = ["abc"] | ||
|
||
mocked_table = Mock() | ||
mocked_get_table.return_value = mocked_table | ||
|
||
mocked_partition_list = [Mock()] | ||
formatted_partitions_location = ["abc"] | ||
mocked__format_partitions.return_value = formatted_partitions_location | ||
|
||
# act | ||
hive_metastore_client.add_partitions_if_not_exists( | ||
db_name=db_name, table_name=table_name, partition_list=mocked_partition_list | ||
) | ||
|
||
# assert | ||
mocked_get_table.assert_called_once_with(dbname=db_name, tbl_name=table_name) | ||
mocked__format_partitions.assert_called_once_with( | ||
partition_list=mocked_partition_list, | ||
table_storage_descriptor=mocked_table.sd, | ||
table_partition_keys=mocked_table.partitionKeys, | ||
) | ||
mocked_add_partitions.assert_called_once_with(formatted_partitions_location) | ||
|
||
@mock.patch.object(HiveMetastoreClient, "get_table") | ||
@mock.patch.object(HiveMetastoreClient, "_format_partitions_location") | ||
@mock.patch.object(HiveMetastoreClient, "add_partitions") | ||
def test_add_partitions_to_table_with_duplicated_partitions( | ||
self, | ||
mocked_add_partitions, | ||
mocked__format_partitions, | ||
mocked_get_table, | ||
hive_metastore_client, | ||
): | ||
# arrange | ||
db_name = "database_name" | ||
table_name = "table_name" | ||
|
||
mocked_table = Mock() | ||
mocked_table.sd = "" | ||
mocked_table.partitionKeys = "" | ||
mocked_get_table.return_value = mocked_table | ||
|
||
mocked_partition_list = [Mock()] | ||
formatted_partitions_location = ["abc"] | ||
mocked__format_partitions.return_value = formatted_partitions_location | ||
|
||
mocked_add_partitions.side_effect = AlreadyExistsException() | ||
|
||
# act | ||
hive_metastore_client.add_partitions_to_table( | ||
hive_metastore_client.add_partitions_if_not_exists( | ||
db_name=db_name, table_name=table_name, partition_list=mocked_partition_list | ||
) | ||
|
||
|
@@ -186,6 +224,26 @@ def test_add_partitions_to_table( | |
) | ||
mocked_add_partitions.assert_called_once_with(formatted_partitions_location) | ||
|
||
@mock.patch.object(HiveMetastoreClient, "get_table") | ||
@mock.patch.object(HiveMetastoreClient, "_format_partitions_location") | ||
@mock.patch.object(HiveMetastoreClient, "add_partitions") | ||
def test_add_partitions_to_table_with_invalid_partitions( | ||
self, | ||
mocked_add_partitions, | ||
mocked__format_partitions, | ||
mocked_get_table, | ||
hive_metastore_client, | ||
): | ||
# assert | ||
with raises(ValueError): | ||
# act | ||
hive_metastore_client.add_partitions_if_not_exists( | ||
db_name=ANY, table_name=ANY, partition_list=[] | ||
) | ||
mocked_get_table.assert_not_called() | ||
mocked__format_partitions.assert_not_called() | ||
mocked_add_partitions.assert_not_called() | ||
Comment on lines
+230
to
+245
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. niceee |
||
|
||
@mock.patch.object(HiveMetastoreClient, "_validate_lists_length") | ||
def test_format_partitions_location( | ||
self, mocked_validate_lists_length, hive_metastore_client | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
β€οΈ