[Presto] Handle uncaught exception in get_create_view (#8304)

This commit is contained in:
Erik Ritter 2019-10-01 07:45:12 -10:00 committed by GitHub
parent f21cc63030
commit 8c708037e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 5 deletions

View File

@ -1036,18 +1036,21 @@ class PrestoEngineSpec(BaseEngineSpec):
:param schema: Schema name
:param table: Table (view) name
"""
from pyhive.exc import DatabaseError
engine = cls.get_engine(database, schema)
with closing(engine.raw_connection()) as conn:
with closing(conn.cursor()) as cursor:
sql = f"SHOW CREATE VIEW {schema}.{table}"
cls.execute(cursor, sql)
try:
cls.execute(cursor, sql)
polled = cursor.poll()
except Exception: # not a VIEW
while polled:
time.sleep(0.2)
polled = cursor.poll()
except DatabaseError: # not a VIEW
return None
while polled:
time.sleep(0.2)
polled = cursor.poll()
rows = cls.fetch_data(cursor, 1)
return rows[0][0]