Browse Source

HUE-2686 [impala] Explain button is erroring

Romain Rigaux 10 years ago
parent
commit
570f8b42e8

+ 4 - 4
apps/beeswax/src/beeswax/server/hive_server2_lib.py

@@ -601,8 +601,8 @@ class HiveServerClient:
     return self.execute_query_statement(statement=query.query['query'], max_rows=max_rows, configuration=configuration)
 
 
-  def execute_query_statement(self, statement, max_rows=1000, configuration={}):
-    (results, schema), operation_handle = self.execute_statement(statement=statement, max_rows=max_rows, configuration=configuration)
+  def execute_query_statement(self, statement, max_rows=1000, configuration={}, orientation=TFetchOrientation.FETCH_FIRST):
+    (results, schema), operation_handle = self.execute_statement(statement=statement, max_rows=max_rows, configuration=configuration, orientation=orientation)
     return HiveServerDataTable(results, schema, operation_handle, self.query_server)
 
 
@@ -625,7 +625,7 @@ class HiveServerClient:
     return self.execute_async_statement(statement=query_statement, confOverlay=configuration)
 
 
-  def execute_statement(self, statement, max_rows=1000, configuration={}, orientation=TFetchOrientation.FETCH_FIRST):
+  def execute_statement(self, statement, max_rows=1000, configuration={}, orientation=TFetchOrientation.FETCH_NEXT):
     if self.query_server['server_name'] == 'impala' and self.query_server['QUERY_TIMEOUT_S'] > 0:
       configuration['QUERY_TIMEOUT_S'] = str(self.query_server['QUERY_TIMEOUT_S'])
 
@@ -711,7 +711,7 @@ class HiveServerClient:
   def explain(self, query):
     query_statement = query.get_query_statement(0)
     configuration = self._get_query_configuration(query)
-    return self.execute_query_statement(statement='EXPLAIN %s' % query_statement, configuration=configuration)
+    return self.execute_query_statement(statement='EXPLAIN %s' % query_statement, configuration=configuration, orientation=TFetchOrientation.FETCH_NEXT)
 
 
   def get_log(self, operation_handle):

+ 2 - 2
apps/beeswax/src/beeswax/test_base.py

@@ -205,11 +205,11 @@ def is_finished(response):
   return 'error' in status or status.get('isSuccess') or status.get('isFailure')
 
 
-def fetch_query_result_data(client, status_response, n=0):
+def fetch_query_result_data(client, status_response, n=0, server_name='beeswax'):
   # Take a wait_for_query_to_finish() response in input
   status = json.loads(status_response.content)
 
-  response = client.get("/beeswax/results/%(id)s/%(n)s?format=json" % {'id': status.get('id'), 'n': n})
+  response = client.get("/%(server_name)s/results/%(id)s/%(n)s?format=json" % {'server_name': server_name, 'id': status.get('id'), 'n': n})
   content = json.loads(response.content)
 
   return content

+ 12 - 2
apps/impala/src/impala/tests.py

@@ -15,6 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import json
 import os
 import re
 import sys
@@ -159,7 +160,7 @@ class TestImpalaIntegration:
 
     # Check that we multiple fetches get all the result set
     while len(results) < 5:
-      content = fetch_query_result_data(self.client, response, n=len(results)) # We get less than 5 results most of the time, so increase offset
+      content = fetch_query_result_data(self.client, response, n=len(results), server_name='impala') # We get less than 5 results most of the time, so increase offset
       results += content['results']
 
     assert_equal([1, 2, 3, 4, 5], [col[0] for col in results])
@@ -168,11 +169,20 @@ class TestImpalaIntegration:
     results_start_over = []
 
     while len(results_start_over) < 5:
-      content = fetch_query_result_data(self.client, response, n=len(results_start_over))
+      content = fetch_query_result_data(self.client, response, n=len(results_start_over), server_name='impala')
       results_start_over += content['results']
 
     assert_equal(results_start_over, results)
 
+  def test_explain(self):
+    QUERY = """
+      SELECT * FROM tweets ORDER BY row_num;
+    """
+    response = _make_query(self.client, QUERY, database=self.DATABASE, local=False, server_name='impala', submission_type='Explain')
+    json_response = json.loads(response.content)
+    assert_true('MERGING-EXCHANGE' in json_response['explanation'], json_response)
+    assert_true('SCAN HDFS' in json_response['explanation'], json_response)
+
 
 # Could be refactored with SavedQuery.create_empty()
 def create_saved_query(app_name, owner):