Skip to content

Commit

Permalink
[plugins][vdk-impala] Improve error handling to properly handle view …
Browse files Browse the repository at this point in the history
…errors

Currently, the impala error handling logic fails to properly handle
TableAlreadyExist exceptions, in cases where these are caused while processing
`CREATE VIEW` sql queries.

This change modifies the error handling logic to properly handle exceptions
caused while processing `CREATE VIEW` queries.

Testing Done: Added unit test.

Signed-off-by: Andon Andonov <andonova@vmware.com>
  • Loading branch information
doks5 committed Feb 18, 2022
1 parent aef2042 commit 73c714b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def get_fully_qualified_table_name(exception_to_match: Exception):
if "." not in fully_qualified_table_name:
try:
schema_match = re.search(
r"create table\b\s`?(\w+)`?\.{}".format(
r"create (?:table|view)\b\s`?(\w+)`?\.{}".format(
fully_qualified_table_name
),
recovery_cursor.get_managed_operation().get_operation(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,28 @@ def test_AlreadyExistsException_table_already_exists(patched_time_sleep):
call(original_query),
]
mock_native_cursor.execute.assert_has_calls(expected_calls)


@patch("time.sleep", return_value=None)
def test_AlreadyExistsException_view_already_exists(patched_time_sleep):
error_message = "AlreadyExistsException: Table test_table already exists"
exception = HiveServer2Error(error_message)
original_query = (
"CREATE VIEW test_schema.test_table AS "
"SELECT * "
"FROM test_mart.view_test_table;"
)
(mock_native_cursor, _, _, mock_recovery_cursor, _) = populate_mock_managed_cursor(
mock_exception_to_recover=exception, mock_operation=original_query
)

error_handler = ImpalaErrorHandler(logging.getLogger(), num_retries=1)
error_handler.handle_error(
caught_exception=exception, recovery_cursor=mock_recovery_cursor
)

expected_calls = [
call("invalidate metadata test_schema.test_table"),
call(original_query),
]
mock_native_cursor.execute.assert_has_calls(expected_calls)

0 comments on commit 73c714b

Please sign in to comment.