فهرست منبع

[presto] Avoid progress report exception when query just stopped

Romain Rigaux 4 سال پیش
والد
کامیت
25720e11a2
1فایلهای تغییر یافته به همراه13 افزوده شده و 5 حذف شده
  1. 13 5
      desktop/libs/notebook/src/notebook/connectors/sql_alchemy.py

+ 13 - 5
desktop/libs/notebook/src/notebook/connectors/sql_alchemy.py

@@ -307,19 +307,25 @@ class SqlAlchemyApi(Api):
 
     return response
 
+
   @query_error_handler
   def progress(self, notebook, snippet, logs=''):
+    progress = 50
     if self.options['url'].startswith('presto://'):
       guid = snippet['result']['handle']['guid']
       handle = CONNECTIONS.get(guid)
-      if not handle:
-        return 50
-      stats = handle['result'].cursor.poll()
+      stats = None
+      try:
+        if handle:
+          stats = handle['result'].cursor.poll()
+      except AssertionError as e:
+        LOG.warn('Query probably not running anymore: %s' % e)
       if not stats:
-        return 100
+        progress = 100
       stats = stats.get('stats', {})
       return stats.get('completedSplits', 0) * 100 // stats.get('totalSplits', 1)
-    return 50
+    return progress
+
 
   @query_error_handler
   def fetch_result(self, notebook, snippet, rows, start_over):
@@ -340,6 +346,7 @@ class SqlAlchemyApi(Api):
       'type': 'table'
     }
 
+
   def _assign_types(self, results, meta):
     result = results and results[0]
     if result:
@@ -357,6 +364,7 @@ class SqlAlchemyApi(Api):
         else:
           meta[index]['type'] = 'STRING_TYPE'
 
+
   @query_error_handler
   def fetch_result_metadata(self):
     pass