瀏覽代碼

HUE-4963 [metastore] Convert partition browsing to the new editor

Romain Rigaux 8 年之前
父節點
當前提交
7bbe23489a

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

@@ -813,7 +813,7 @@ class HiveServer2Dbms(object):
     return self.client.get_partitions(db_name, table.name, partition_spec, max_parts=max_parts, reverse_sort=reverse_sort)
 
 
-  def get_partition(self, db_name, table_name, partition_spec):
+  def get_partition(self, db_name, table_name, partition_spec, generate_ddl_only=False):
     table = self.get_table(db_name, table_name)
     partitions = self.get_partitions(db_name, table, partition_spec=partition_spec)
 
@@ -825,7 +825,10 @@ class HiveServer2Dbms(object):
 
     hql = "SELECT * FROM `%s`.`%s` WHERE %s" % (db_name, table_name, partition_query)
 
-    return self.execute_statement(hql)
+    if generate_ddl_only:
+      return hql
+    else:
+      return self.execute_statement(hql)
 
 
   def describe_partition(self, db_name, table_name, partition_spec):

+ 19 - 9
apps/metastore/src/metastore/templates/metastore.mako

@@ -197,18 +197,24 @@ ${ components.menubar() }
       <tbody>
       <!-- ko foreach: values -->
       <tr>
-        <td data-bind="text: $index()+1"></td>
-        <td><a data-bind="attr: {'href': readUrl }, text: '[\'' + columns.join('\',\'') + '\']'"></a></td>
+        <td data-bind="text: $index() + 1"></td>
+        <td>
+          <!-- ko if: !IS_HUE_4 -->
+            <a data-bind="click: function() { browsePartition(notebookUrl, 'query'); }, text: '[\'' + columns.join('\',\'') + '\']'" href="javascript:void(0)"></a>
+          <!-- /ko -->
+          <!-- ko if:  IS_HUE_4 -->
+            <a data-bind="attr: {'href': readUrl }, text: '[\'' + columns.join('\',\'') + '\']'"></a>
+          <!-- /ko -->
+        </td>
         <td data-bind="text: partitionSpec"></td>
         <td>
-          <a data-bind="attr: {'href': readUrl }"><i class="fa fa-th"></i> ${_('Data')}</a>
           <!-- ko if: IS_HUE_4 -->
-            <a data-bind="click: function () { browsePartitionFiles(browseUrl); }" href="javascript:void(0)" title="${_('Browse partition files')}">
-              <i class="fa fa-file-o"></i> ${_('Files')}
+            <a data-bind="click: function () { browsePartition(browseUrl, 'files'); }" href="javascript:void(0)" title="${_('Browse partition files')}">
+              ${_('Files')}
             </a>
           <!-- /ko -->
           <!-- ko if: ! IS_HUE_4 -->
-            <a data-bind="attr: {'href': browseUrl }" title="${_('Browse partition files')}"><i class="fa fa-file-o"></i> ${_('Files')}</a>
+            <a data-bind="attr: {'href': browseUrl }" title="${_('Browse partition files')}">${_('Files')}</a>
           <!-- /ko -->
         </td>
       </tr>
@@ -231,7 +237,7 @@ ${ components.menubar() }
     <tbody>
       <!-- ko foreach: rows -->
         <tr>
-          <td data-bind="text: $index()+1"></td>
+          <td data-bind="text: $index() + 1"></td>
           <!-- ko foreach: $data -->
             <td data-bind="text: $data"></td>
           <!-- /ko -->
@@ -1164,12 +1170,16 @@ ${ components.menubar() }
     });
   }
 
-  function browsePartitionFiles(url) {
+  function browsePartition(url, type) {
     $.get(url, {
       format: "json"
     },function(resp) {
       if (resp.uri_path) {
-        huePubSub.publish('open.fb.folder', resp.uri_path.replace(/\/filebrowser\/view=/g, '') );
+        if (type == 'file') {
+          huePubSub.publish('open.fb.folder', resp.uri_path.replace(/\/filebrowser\/view=/g, '') );
+        } else {
+          huePubSub.publish('open.link', resp.uri_path);
+        }
       } else if (resp.message) {
         $(document).trigger("error", resp.message);
       }

+ 5 - 0
apps/metastore/src/metastore/views.py

@@ -532,6 +532,11 @@ def _massage_partition(database, table, partition):
         'database': database,
         'table': table.name,
         'partition_spec': urllib.quote(partition.partition_spec)
+    }),
+   'notebookUrl': reverse('notebook:browse', kwargs={
+        'database': database,
+        'table': table.name,
+        'partition_spec': urllib.quote(partition.partition_spec)
     })
   }
 

+ 7 - 2
desktop/libs/notebook/src/notebook/connectors/hiveserver2.py

@@ -23,6 +23,7 @@ import logging
 import re
 import StringIO
 import struct
+import urllib
 
 from django.core.urlresolvers import reverse
 from django.utils.translation import ugettext as _
@@ -704,14 +705,18 @@ DROP TABLE IF EXISTS `%(table)s`;
     )
 
 
-  def get_select_star_query(self, snippet, database, table):
+  def get_browse_query(self, snippet, database, table, partition_spec=None):
     db = self._get_db(snippet)
     table = db.get_table(database, table)
     if table.is_impala_only:
       snippet['type'] = 'impala'
       db = self._get_db(snippet)
 
-    return db.get_select_star_query(database, table, limit=100)
+    if partition_spec is not None:
+      decoded_spec = urllib.unquote(partition_spec)
+      return db.get_partition(database, table.name, decoded_spec, generate_ddl_only=True)
+    else:
+      return db.get_select_star_query(database, table, limit=100)
 
 
   def _get_handle(self, snippet):

+ 1 - 1
desktop/libs/notebook/src/notebook/connectors/rdbms.py

@@ -155,7 +155,7 @@ class RdbmsApi(Api):
     return response
 
   @query_error_handler
-  def get_select_star_query(self, snippet, database, table):
+  def get_browse_query(self, snippet, database, table, partition_spec=None):
     return "SELECT * FROM `%s`.`%s` LIMIT 1000" % (database, table)
 
 

+ 1 - 1
desktop/libs/notebook/src/notebook/urls.py

@@ -44,7 +44,7 @@ urlpatterns = patterns('notebook.views',
   url(r'^editor/?$', 'editor', name='editor'),
   url(r'^editor_embeddable/?$', 'editor_embeddable', name='editor_embeddable'),
   url(r'^editor_m/?$', 'editor_m', name='editor_m'),
-  url(r'^browse/(?P<database>\w+)/(?P<table>\w+)/?$', 'browse', name='browse'),
+  url(r'^browse/(?P<database>\w+)/(?P<table>\w+)/(?P<partition_spec>.+?)?$', 'browse', name='browse'),
   url(r'^execute_and_watch/?$', 'execute_and_watch', name='execute_and_watch'),
 )
 

+ 4 - 3
desktop/libs/notebook/src/notebook/views.py

@@ -140,12 +140,13 @@ def new(request):
   return notebook(request)
 
 
-def browse(request, database, table):
+def browse(request, database, table, partition_spec=None):
   snippet = {'type': 'hive'}
-  sql_select = get_api(request, snippet).get_select_star_query(snippet, database, table)
+
+  statement = get_api(request, snippet).get_browse_query(snippet, database, table, partition_spec)
 
   editor_type = snippet['type']
-  editor = make_notebook(name='Browse', editor_type=editor_type, statement=sql_select, status='ready-execute')
+  editor = make_notebook(name='Browse', editor_type=editor_type, statement=statement, status='ready-execute')
 
   return render('editor.mako', request, {
       'notebooks_json': json.dumps([editor.get_data()]),