Browse Source

HUE-6296 [optimizer] Properly skip query history who did not compile

Romain Rigaux 8 years ago
parent
commit
f553397
1 changed files with 6 additions and 4 deletions
  1. 6 4
      desktop/libs/metadata/src/metadata/optimizer_api.py

+ 6 - 4
desktop/libs/metadata/src/metadata/optimizer_api.py

@@ -305,10 +305,12 @@ def _convert_queries(queries_data):
 
   for query_data in queries_data:
     try:
-      original_query_id = '%s:%s' % struct.unpack(b"QQ", base64.decodestring(query_data['snippets'][0]['result']['handle']['guid']))
-      execution_time = query_data['snippets'][0]['result']['executionTime'] * 100
-      statement = ' '.join([line for line in _get_statement(query_data).strip().splitlines() if not line.strip().startswith('--')])
-      queries.append((original_query_id, execution_time, statement, query_data['snippets'][0].get('database', 'default').strip()))
+      snippet = query_data['snippets'][0]
+      if 'guid' in snippet['result']['handle']: # Not failed query
+        original_query_id = '%s:%s' % struct.unpack(b"QQ", base64.decodestring(snippet['result']['handle']['guid']))
+        execution_time = snippet['result']['executionTime'] * 100 if snippet['status'] in ('available', 'expired') else -1
+        statement = ' '.join([line for line in _get_statement(query_data).strip().splitlines() if not line.strip().startswith('--')])
+        queries.append((original_query_id, execution_time, statement, snippet.get('database', 'default').strip()))
     except Exception, e:
       LOG.warning('Skipping upload of %s: %s' % (query_data['uuid'], e))