Add query id debugging for HS2

As part of debugging IMPALA-9098, I realised we don't print the query ID
for HS2 queries, which makes it harder finding queries in the logs.

This pulls the query ID out of the Impyla handle and prints it in
the expected form (I used the same logic as in impala shell).

Change-Id: I5d34128a7a2b69ca9043fcf5e919e9dd2a9f452b
Reviewed-on: http://gerrit.cloudera.org:8080/14607
Reviewed-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
diff --git a/tests/common/impala_connection.py b/tests/common/impala_connection.py
index f1a33bb..a0bb624 100644
--- a/tests/common/impala_connection.py
+++ b/tests/common/impala_connection.py
@@ -341,7 +341,9 @@
       raise NotImplementedError("Not yet implemented for HS2 - authentication")
     try:
       self.__cursor.execute_async(sql_stmt, configuration=self.__query_options)
-      return OperationHandle(self.__cursor, sql_stmt)
+      handle = OperationHandle(self.__cursor, sql_stmt)
+      LOG.info("Started query {0}".format(self.get_query_id(handle)))
+      return handle
     except Exception:
       self.__cursor.close_operation()
       raise
@@ -351,6 +353,13 @@
     cursor = operation_handle.get_handle()
     return cursor.cancel_operation(reset_state=False)
 
+  def get_query_id(self, operation_handle):
+    """Return the string representation of the query id."""
+    guid_bytes = \
+        operation_handle.get_handle()._last_operation.handle.operationId.guid
+    return "{0}:{1}".format(guid_bytes[7::-1].encode('hex_codec'),
+                            guid_bytes[16:7:-1].encode('hex_codec'))
+
   def get_state(self, operation_handle):
     LOG.info("-- getting state for operation: {0}".format(operation_handle))
     cursor = operation_handle.get_handle()