فهرست منبع

[hive] Revert to TGetSchemasReq() instead of SHOW DATABASES

HiveServer2 is faster and we avoid the session lock this way
Romain Rigaux 10 سال پیش
والد
کامیت
72edd31
2فایلهای تغییر یافته به همراه13 افزوده شده و 20 حذف شده
  1. 5 17
      apps/beeswax/src/beeswax/server/dbms.py
  2. 8 3
      apps/beeswax/src/beeswax/server/hive_server2_lib.py

+ 5 - 17
apps/beeswax/src/beeswax/server/dbms.py

@@ -143,27 +143,15 @@ class HiveServer2Dbms(object):
 
 
   def get_databases(self, database_names='*'):
-    hql = "SHOW DATABASES"  # self.client.get_databases() is too slow
     if database_names != '*':
-      identifier = self.to_matching_wildcard(database_names)
-      hql += " LIKE '%s'" % (identifier)
+      database_names = self.to_matching_wildcard(database_names)
 
-    query = hql_query(hql)
-    timeout = SERVER_CONN_TIMEOUT.get()
+    databases = self.client.get_databases(schemaName=database_names)
 
-    handle = self.execute_and_wait(query, timeout_sec=timeout)
+    if len(databases) <= APPLY_NATURAL_SORT_MAX.get():
+      databases = apply_natural_sort(databases)
 
-    if handle:
-      result = self.fetch(handle, rows=5000)
-      self.close(handle)
-      
-      databases = [row[0] for row in result.rows()]
-
-      if len(databases) <= APPLY_NATURAL_SORT_MAX.get():
-        databases = apply_natural_sort(databases)
-      return databases
-    else:
-      return []
+    return databases
 
 
   def get_database(self, database):

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

@@ -649,9 +649,14 @@ class HiveServerClient:
     return self._client.CloseSession(req)
 
 
-  def get_databases(self):
+  def get_databases(self, schemaName=None):
     # GetCatalogs() is not implemented in HS2
     req = TGetSchemasReq()
+    if schemaName is not None:
+      req.schemaName = schemaName
+    if self.query_server['server_name'] == 'impala':
+      req.schemaName = None
+
     res = self.call(self._client.GetSchemas, req)
 
     results, schema = self.fetch_result(res.operationHandle, orientation=TFetchOrientation.FETCH_NEXT, max_rows=5000)
@@ -1065,9 +1070,9 @@ class HiveServerClientCompatible(object):
       return self._client.fetch_log(operationHandle, orientation=orientation, max_rows=-1)
 
 
-  def get_databases(self):
+  def get_databases(self, schemaName=None):
     col = 'TABLE_SCHEM'
-    return [table[col] for table in self._client.get_databases()]
+    return [table[col] for table in self._client.get_databases(schemaName)]
 
 
   def get_database(self, database):