瀏覽代碼

HUE-8796 [hive] Remove in place handle guid base64 conversion

(cherry picked from commit 44b938a2e748b4d99be164fec9026f3f1c9a6292)
jdesjean 6 年之前
父節點
當前提交
d39dd642ba

+ 4 - 1
desktop/core/src/desktop/lib/thrift_util.py

@@ -15,7 +15,7 @@
 # See the License for the specific language governing permissions and
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 #
 #
-
+import base64
 import Queue
 import Queue
 import logging
 import logging
 import socket
 import socket
@@ -541,6 +541,9 @@ def _unpack_guid_secret_in_handle(str_args):
 def unpack_guid(guid):
 def unpack_guid(guid):
   return "%016x:%016x" % struct.unpack(b"QQ", guid)
   return "%016x:%016x" % struct.unpack(b"QQ", guid)
 
 
+def unpack_guid_base64(guid):
+  return "%016x:%016x" % struct.unpack(b"QQ", base64.decodestring(guid))
+
 def simpler_string(thrift_obj):
 def simpler_string(thrift_obj):
   """
   """
   Strips out nulls and empty arrays from the string representation.
   Strips out nulls and empty arrays from the string representation.

+ 8 - 7
desktop/libs/notebook/src/notebook/connectors/hiveserver2.py

@@ -35,7 +35,7 @@ from desktop.lib.exceptions import StructuredException
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.i18n import force_unicode, smart_str
 from desktop.lib.i18n import force_unicode, smart_str
 from desktop.lib.rest.http_client import RestException
 from desktop.lib.rest.http_client import RestException
-from desktop.lib.thrift_util import unpack_guid
+from desktop.lib.thrift_util import unpack_guid, unpack_guid_base64
 from desktop.models import DefaultConfiguration, Document2
 from desktop.models import DefaultConfiguration, Document2
 from metadata.optimizer_client import OptimizerApi
 from metadata.optimizer_client import OptimizerApi
 
 
@@ -442,7 +442,7 @@ class HS2Api(Api):
         'finished': job.get('finished', False)
         'finished': job.get('finished', False)
       } for job in jobs_with_state]
       } for job in jobs_with_state]
     elif snippet['type'] == 'impala' and ENABLE_QUERY_BROWSER.get():
     elif snippet['type'] == 'impala' and ENABLE_QUERY_BROWSER.get():
-      query_id = unpack_guid(snippet['result']['handle']['guid'])
+      query_id = unpack_guid_base64(snippet['result']['handle']['guid'])
       progress = min(self.progress(snippet, logs), 99) if snippet['status'] != 'available' and snippet['status'] != 'success' else 100
       progress = min(self.progress(snippet, logs), 99) if snippet['status'] != 'available' and snippet['status'] != 'success' else 100
       jobs = [{
       jobs = [{
         'name': query_id,
         'name': query_id,
@@ -766,17 +766,18 @@ DROP TABLE IF EXISTS `%(table)s`;
 
 
   def _get_handle(self, snippet):
   def _get_handle(self, snippet):
     try:
     try:
-      snippet['result']['handle']['secret'], snippet['result']['handle']['guid'] = HiveServerQueryHandle.get_decoded(snippet['result']['handle']['secret'], snippet['result']['handle']['guid'])
+      handle = snippet['result']['handle'].copy()
+      handle['secret'], handle['guid'] = HiveServerQueryHandle.get_decoded(handle['secret'], handle['guid'])
     except KeyError:
     except KeyError:
       raise Exception('Operation has no valid handle attached')
       raise Exception('Operation has no valid handle attached')
     except binascii.Error:
     except binascii.Error:
       LOG.warn('Handle already base 64 decoded')
       LOG.warn('Handle already base 64 decoded')
 
 
-    for key in snippet['result']['handle'].keys():
+    for key in handle.keys():
       if key not in ('log_context', 'secret', 'has_result_set', 'operation_type', 'modified_row_count', 'guid'):
       if key not in ('log_context', 'secret', 'has_result_set', 'operation_type', 'modified_row_count', 'guid'):
-        snippet['result']['handle'].pop(key)
+        handle.pop(key)
 
 
-    return HiveServerQueryHandle(**snippet['result']['handle'])
+    return HiveServerQueryHandle(**handle)
 
 
 
 
   def _get_db(self, snippet, async=False, cluster=None):
   def _get_db(self, snippet, async=False, cluster=None):
@@ -877,7 +878,7 @@ DROP TABLE IF EXISTS `%(table)s`;
     guid = None
     guid = None
     if 'result' in snippet and 'handle' in snippet['result'] and 'guid' in snippet['result']['handle']:
     if 'result' in snippet and 'handle' in snippet['result'] and 'guid' in snippet['result']['handle']:
       try:
       try:
-        guid = unpack_guid(base64.decodestring(snippet['result']['handle']['guid']))
+        guid = unpack_guid_base64(snippet['result']['handle']['guid'])
       except Exception, e:
       except Exception, e:
         LOG.warn('Failed to decode operation handle guid: %s' % e)
         LOG.warn('Failed to decode operation handle guid: %s' % e)
     else:
     else: