Prechádzať zdrojové kódy

HUE-5129 [metastore] Backend to propose Kudu column properties like primary keys

Romain Rigaux 9 rokov pred
rodič
commit
5705bad

+ 12 - 0
apps/beeswax/src/beeswax/server/dbms.py

@@ -491,6 +491,18 @@ class HiveServer2Dbms(object):
       return result
       return result
 
 
 
 
+  def get_table_describe(self, database, table):
+    hql = 'DESCRIBE `%s`.`%s`' % (database, table)
+
+    query = hql_query(hql)
+    handle = self.execute_and_wait(query, timeout_sec=5.0)
+
+    if handle:
+      result = self.fetch(handle, rows=100)
+      self.close(handle)
+      return result
+
+
   def get_top_terms(self, database, table, column, limit=30, prefix=None):
   def get_top_terms(self, database, table, column, limit=30, prefix=None):
     limit = min(limit, 100)
     limit = min(limit, 100)
     prefix_match = ''
     prefix_match = ''

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

@@ -118,7 +118,7 @@ class HiveServerTable(Table):
     except:
     except:
       # Impala does not have it
       # Impala does not have it
       return rows
       return rows
-
+  
   def _get_partition_column(self):
   def _get_partition_column(self):
     rows = self.describe
     rows = self.describe
     try:
     try:
@@ -790,7 +790,7 @@ class HiveServerClient:
     req = TGetTablesReq(schemaName=database, tableName=table_name)
     req = TGetTablesReq(schemaName=database, tableName=table_name)
     res = self.call(self._client.GetTables, req)
     res = self.call(self._client.GetTables, req)
 
 
-    table_results, table_schema = self.fetch_result(res.operationHandle, orientation=TFetchOrientation.FETCH_NEXT)
+    table_results, table_schema = self.fetch_result(res.operationHandle, orientation=TFetchOrientation.FETCH_NEXT)    
     self.close_operation(res.operationHandle)
     self.close_operation(res.operationHandle)
 
 
     if partition_spec:
     if partition_spec:

+ 3 - 0
apps/metastore/src/metastore/templates/metastore.mako

@@ -124,6 +124,9 @@ ${ components.menubar() }
           <td title="${ _("Scroll to the column") }">
           <td title="${ _("Scroll to the column") }">
             <!-- ko if: $root.database().table().samples.loading() -->
             <!-- ko if: $root.database().table().samples.loading() -->
             <span data-bind="text: name"></span>
             <span data-bind="text: name"></span>
+            <!-- ko if: typeof primary_key !== 'undefined' -->
+              <i class="fa fa-key"></i>
+            <!-- /ko -->
             <!-- /ko -->
             <!-- /ko -->
             <!-- ko ifnot: $root.database().table().samples.loading() -->
             <!-- ko ifnot: $root.database().table().samples.loading() -->
             <a href="javascript:void(0)" class="column-selector" data-bind="text: name, click: scrollToColumn"></a>
             <a href="javascript:void(0)" class="column-selector" data-bind="text: name, click: scrollToColumn"></a>

+ 17 - 1
apps/metastore/src/metastore/views.py

@@ -254,11 +254,27 @@ def describe_table(request, database, table):
       raise PopupException(_("Hive Error"), detail=e)
       raise PopupException(_("Hive Error"), detail=e)
 
 
   if request.REQUEST.get("format", "html") == "json":
   if request.REQUEST.get("format", "html") == "json":
+    cols = []
+    extra_col_options = {}
+
+    if table.is_impala_only: # Expand columns information
+      query_server = get_query_server_config('impala')
+      db = dbms.get(request.user, query_server)
+
+      col_options = db.get_table_describe(database, table.name)
+      extra_col_options = dict([(col[0], dict(zip(col_options.cols(), col))) for col in col_options.rows()])
+
+    for col in table.cols:
+      col_props = {'name': col.name, 'type': col.type, 'comment': col.comment}
+      if extra_col_options:
+        col_props.update(extra_col_options.get(col.name, {}))
+      cols.append(col_props)
+
     return JsonResponse({
     return JsonResponse({
         'status': 0,
         'status': 0,
         'name': table.name,
         'name': table.name,
         'partition_keys': [{'name': part.name, 'type': part.type} for part in table.partition_keys],
         'partition_keys': [{'name': part.name, 'type': part.type} for part in table.partition_keys],
-        'cols': [{'name': col.name, 'type': col.type, 'comment': col.comment} for col in table.cols],
+        'cols': cols,
         'path_location': table.path_location,
         'path_location': table.path_location,
         'hdfs_link': table.hdfs_link,
         'hdfs_link': table.hdfs_link,
         'comment': table.comment,
         'comment': table.comment,