Ver Fonte

HUE-7738 [hive] Adding Thrift call to GetFunctions

Only implemented by Hive, not Impala.
Romain há 5 anos atrás
pai
commit
8e261a8161

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

@@ -125,7 +125,7 @@ def _autocomplete(db, database=None, table=None, column=None, nested=None, query
       cols_extended = massage_columns_for_json(table.cols)
 
       if table.is_impala_only: # Expand Kudu table information
-        if db.client.query_server['server_name'] != 'impala':
+        if db.client.query_server['dialect'] != 'impala':
           query_server = get_query_server_config('impala', connector=cluster)
           db = dbms.get(db.client.user, query_server, cluster=cluster)
 
@@ -180,7 +180,7 @@ def _get_functions(db, database=None):
 
   functions = db.get_functions(prefix=database)
   if functions:
-    rows = escape_rows(functions.rows(), nulls_only=True)
+    rows = escape_rows(functions, nulls_only=True)
     data = [{'name': row[0]} for row in rows]
 
   return data

+ 18 - 11
apps/beeswax/src/beeswax/server/dbms.py

@@ -495,9 +495,11 @@ class HiveServer2Dbms(object):
 
 
   def fetch(self, query_handle, start_over=False, rows=None):
-    no_start_over_support = [config_variable for config_variable in self.get_default_configuration(False)
-                                             if config_variable.key == 'support_start_over'
-                                               and config_variable.value == 'false']
+    no_start_over_support = [
+        config_variable
+        for config_variable in self.get_default_configuration(False)
+        if config_variable.key == 'support_start_over' and config_variable.value == 'false'
+    ]
     if no_start_over_support:
       start_over = False
 
@@ -1096,16 +1098,21 @@ class HiveServer2Dbms(object):
     return self.client.get_configuration()
 
 
-  def get_functions(self, prefix=None):
-    filter = '"%s.*"' % prefix if prefix else '".*"'
-    hql = 'SHOW FUNCTIONS %s' % filter
+  def get_functions(self, prefix=None, database=None):
+    if self.client.query_server['dialect'] == 'impala':
+      if database is None:
+        database = '_impala_builtins'
+      filter = '"%s.*"' % prefix if prefix else '".*"'
+      hql = 'SHOW FUNCTIONS %s' % filter
 
-    query = hql_query(hql)
-    handle = self.execute_and_wait(query, timeout_sec=15.0)
+      query = hql_query(hql)
+      handle = self.execute_and_wait(query, timeout_sec=15.0)
 
-    if handle:
-      result = self.fetch(handle, rows=5000)
-      self.close(handle)
+      if handle:
+        result = self.fetch(handle, rows=5000).rows()
+        self.close(handle)
+    else:
+      result = self.client.get_functions('aa', 'bb')
 
     return result
 

+ 23 - 3
apps/beeswax/src/beeswax/server/hive_server2_lib.py

@@ -28,7 +28,7 @@ from django.utils.translation import ugettext as _
 from TCLIService import TCLIService
 from TCLIService.ttypes import TOpenSessionReq, TGetTablesReq, TFetchResultsReq, TStatusCode, TGetResultSetMetadataReq, \
   TGetColumnsReq, TTypeId, TExecuteStatementReq, TGetOperationStatusReq, TFetchOrientation, \
-  TCloseSessionReq, TGetSchemasReq, TGetLogReq, TCancelOperationReq, TCloseOperationReq, TFetchResultsResp, TRowSet
+  TCloseSessionReq, TGetSchemasReq, TGetLogReq, TCancelOperationReq, TCloseOperationReq, TFetchResultsResp, TRowSet, TGetFunctionsReq
 
 from desktop.lib import python_util, thrift_util
 from desktop.conf import DEFAULT_USER
@@ -935,11 +935,18 @@ class HiveServerClient(object):
     return self.execute_query_statement(statement=query.query['query'], max_rows=max_rows, configuration=configuration, session=session)
 
 
-  def execute_query_statement(self, statement, max_rows=1000, configuration=None, orientation=TFetchOrientation.FETCH_FIRST, close_operation=False, session=None):
+  def execute_query_statement(self, statement, max_rows=1000, configuration=None, orientation=TFetchOrientation.FETCH_FIRST,
+      close_operation=False, session=None):
     if configuration is None:
       configuration = {}
 
-    results, schema, operation_handle, session = self.execute_statement(statement=statement, max_rows=max_rows, configuration=configuration, orientation=orientation, session=session)
+    results, schema, operation_handle, session = self.execute_statement(
+        statement=statement,
+        max_rows=max_rows,
+        configuration=configuration,
+        orientation=orientation,
+        session=session
+    )
 
     if close_operation:
       self.close_operation(operation_handle)
@@ -1174,6 +1181,16 @@ class HiveServerClient(object):
     return dict([(setting['key'], setting['value']) for setting in query.settings])
 
 
+  def get_functions(self, database, table):
+    req = TGetFunctionsReq(functionName='.*')
+    (res, session) = self.call(self._client.GetFunctions, req)
+
+    results, schema = self.fetch_result(res.operationHandle, orientation=TFetchOrientation.FETCH_NEXT)
+    self._close(res.operationHandle, session)
+
+    return results, schema
+
+
 class HiveServerTableCompatible(HiveServerTable):
   """Same API as Beeswax"""
 
@@ -1435,3 +1452,6 @@ class HiveServerClientCompatible(object):
 
   def get_configuration(self):
     return self._client.get_configuration()
+
+  def get_functions(self, database, table):
+    return self._client.get_functions(database, table)