diff --git a/projects/vdk-plugins/vdk-impala/src/vdk/plugin/impala/impala_error_handler.py b/projects/vdk-plugins/vdk-impala/src/vdk/plugin/impala/impala_error_handler.py index c293391d71..76236bccd9 100644 --- a/projects/vdk-plugins/vdk-impala/src/vdk/plugin/impala/impala_error_handler.py +++ b/projects/vdk-plugins/vdk-impala/src/vdk/plugin/impala/impala_error_handler.py @@ -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(), diff --git a/projects/vdk-plugins/vdk-impala/tests/impala_handle_metadata_exception_with_invalidate_and_retry_test.py b/projects/vdk-plugins/vdk-impala/tests/impala_handle_metadata_exception_with_invalidate_and_retry_test.py index e1b9f2e726..6abbea4b6b 100644 --- a/projects/vdk-plugins/vdk-impala/tests/impala_handle_metadata_exception_with_invalidate_and_retry_test.py +++ b/projects/vdk-plugins/vdk-impala/tests/impala_handle_metadata_exception_with_invalidate_and_retry_test.py @@ -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)