fix(Presto): catch DatabaseError when testing Presto views (#25559)

Co-authored-by: Rui Zhao <zhaorui@dropbox.com>
This commit is contained in:
Rui Zhao 2023-10-11 10:31:07 -07:00 committed by GitHub
parent d0f2c5581d
commit be3714e131
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -1268,11 +1268,11 @@ class PrestoEngineSpec(PrestoBaseEngineSpec):
sql = f"SHOW CREATE VIEW {schema}.{table}"
try:
cls.execute(cursor, sql)
rows = cls.fetch_data(cursor, 1)
return rows[0][0]
except DatabaseError: # not a VIEW
return None
rows = cls.fetch_data(cursor, 1)
return rows[0][0]
@classmethod
def get_tracking_url(cls, cursor: Cursor) -> str | None:

View File

@ -925,9 +925,11 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
def test_get_create_view_database_error(self):
from pyhive.exc import DatabaseError
mock_execute = mock.MagicMock(side_effect=DatabaseError())
mock_execute = mock.MagicMock()
mock_fetch_data = mock.MagicMock(side_effect=DatabaseError())
database = mock.MagicMock()
database.get_raw_connection().__enter__().cursor().execute = mock_execute
database.get_raw_connection().__enter__().cursor().fetchall = mock_fetch_data
schema = "schema"
table = "table"
result = PrestoEngineSpec.get_create_view(database, schema=schema, table=table)