Bläddra i källkod

HUE-75 [beeswax] "show partitions" forgets its table pane

Moved show partitions on the left hand menu and added counter
Browse partition is now possible
Enrico Berti 12 år sedan
förälder
incheckning
f9a3089

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

@@ -307,6 +307,17 @@ class Dbms:
 
     return self.client.get_partitions(db_name, table.name, max_parts)
 
+  def get_partition(self, db_name, table_name, partition_id):
+    table = self.get_table(db_name, table_name)
+    partitions = self.get_partitions(db_name, table, max_parts=None)
+    partition_query = ""
+    for idx, key in enumerate(partitions[partition_id].values):
+      partition_query += (idx > 0 and " AND " or "") + table.partition_keys[idx].name + "=" + key
+
+    hql = "SELECT * FROM `%s.%s` WHERE %s" % (db_name, table_name, partition_query)
+
+    return self.execute_statement(hql)
+
 
   def explain(self, statement):
     return self.client.explain(statement)

+ 47 - 25
apps/catalog/src/catalog/templates/describe_partitions.mako

@@ -27,36 +27,58 @@ ${ commonheader(_('Table Partitions: %(tableName)s') % dict(tableName=table.name
 <h1>${_('Partitions')}</h1>
 ${ components.breadcrumbs(breadcrumbs) }
 
-<table class="table table-striped table-condensed datatables">
-  % if partitions:
-    <tr>
-      % for field in table.partition_keys:
-        <th>${field.name}</th>
-      % endfor
-      <th>${_('Path')}</th>
-    </tr>
-    % for partition in partitions:
-      <tr>
-        % for key in partition.values:
-          <td>${key}</td>
-        % endfor
-        <td>
-          <% url = location_to_url(partition.sd.location) %>
-          % if url:
-            <a href="${url}">${partition.sd.location}</a>
+  <div class="row-fluid">
+    <div class="span2">
+      <div class="well sidebar-nav">
+        <ul class="nav nav-list">
+          <li class="nav-header">${_('Actions')}</li>
+          <li><a href="${ url('catalog:describe_table', database=database, table=table.name) }">${_('Show Table')}</a></li>
+          <li style="height: 30px"></li>
+        </ul>
+      </div>
+    </div>
+    <div class="span10">
+      <table class="table table-striped table-condensed datatables">
+          % if partitions:
+          <tr>
+          % for field in table.partition_keys:
+              <th>${field.name}</th>
+          % endfor
+            <th>${_('Path')}</th>
+          </tr>
+          % for partition_id, partition in enumerate(partitions):
+            <tr>
+            % for idx, key in enumerate(partition.values):
+                <td><a href="${ url('catalog:read_partition', database=database, table=table.name, partition_id=partition_id) }" data-row-selector="true">${key}</a></td>
+            % endfor
+            <% location = location_to_url(partition.sd.location) %>
+            % if url:
+                <td data-row-selector-exclude="true">
+                  <a href="${location}">${partition.sd.location}</a>
+                </td>
+            % else:
+                <td>
+                ${partition.sd.location}
+                </td>
+            % endif
+            </tr>
+          % endfor
           % else:
-            ${partition.sd.location}
+            <tr><td>${_('Table has no partitions.')}</td></tr>
           % endif
-        </td>
-      </tr>
-    % endfor
-  % else:
-    <tr><td>${_('Table has no partitions.')}</td></tr>
-  % endif
-</table>
+      </table>
+    </div>
+  </div>
+
 
 </div>
 
 <link rel="stylesheet" href="/catalog/static/css/catalog.css" type="text/css">
 
+<script type="text/javascript" charset="utf-8">
+  $(document).ready(function () {
+    $("a[data-row-selector='true']").jHueRowSelector();
+  });
+</script>
+
 ${ commonfooter(messages) | n,unicode }

+ 5 - 3
apps/catalog/src/catalog/templates/describe_table.mako

@@ -56,7 +56,7 @@ ${ commonheader(_("%s : %s") % (view_or_table_noun, table.name), app_name, user)
     ${ components.breadcrumbs(breadcrumbs) }
 
     <div class="row-fluid">
-        <div class="span3">
+        <div class="span2">
             <div class="well sidebar-nav">
                 <ul class="nav nav-list">
                     <li class="nav-header">${_('Actions')}</li>
@@ -64,10 +64,13 @@ ${ commonheader(_("%s : %s") % (view_or_table_noun, table.name), app_name, user)
                     <li><a href="${ url('catalog:read_table', database=database, table=table.name) }">${_('Browse Data')}</a></li>
                     <li><a href="#dropTable" data-toggle="modal">${_('Drop')} ${view_or_table_noun}</a></li>
                     <li><a href="${ table.hdfs_link }" rel="${ table.path_location }">${_('View File Location')}</a></li>
+                    % if table.partition_keys:
+                      <li><a href="${ url('catalog:describe_partitions', database=database, table=table.name) }">${_('Show Partitions')} (${ len(partitions) })</a></li>
+                    % endif
                 </ul>
             </div>
         </div>
-        <div class="span9">
+        <div class="span10">
             % if table.comment:
                 <div class="alert alert-info">${ _('Comment:') } ${ table.comment }</div>
             % endif
@@ -90,7 +93,6 @@ ${ commonheader(_("%s : %s") % (view_or_table_noun, table.name), app_name, user)
                 % if table.partition_keys:
                   <div class="tab-pane" id="partitionColumns">
                     ${column_table(table.partition_keys)}
-                    <a href="${ url('catalog:describe_partitions', database=database, table=table.name) }">${_('Show Partitions')}</a>
                   </div>
                 % endif
 

+ 2 - 1
apps/catalog/src/catalog/urls.py

@@ -29,4 +29,5 @@ urlpatterns = patterns('catalog.views',
   url(r'^table/(?P<database>\w+)/(?P<table>\w+)/partitions$', 'describe_partitions', name='describe_partitions'),
   url(r'^table/(?P<database>\w+)/(?P<table>\w+)/load$', 'load_table', name='load_table'),
   url(r'^table/(?P<database>\w+)/(?P<table>\w+)/read$', 'read_table', name='read_table'),
-)
+  url(r'^table/(?P<database>\w+)/(?P<table>\w+)/partitions/(?P<partition_id>\w+)$', 'read_partition', name='read_partition'),
+)

+ 16 - 2
apps/catalog/src/catalog/views.py

@@ -119,6 +119,9 @@ def describe_table(request, database, table):
   table_data = ''
 
   table = db.get_table(database, table)
+  partitions = None
+  if table.partition_keys:
+    partitions = db.get_partitions(database, table, max_parts=None)
 
   try:
     table_data = db.get_sample(database, table)
@@ -137,6 +140,7 @@ def describe_table(request, database, table):
       },
     ],
     'table': table,
+    'partitions': partitions,
     'sample': table_data and table_data.rows(),
     'error_message': error_message,
     'database': database,
@@ -174,7 +178,17 @@ def read_table(request, database, table):
     url = reverse('beeswax:watch_query', args=[history.id]) + '?context=table:%s:%s' % (table.name, database)
     return redirect(url)
   except Exception, e:
-    raise PopupException(_('Can read table'), detail=e)
+    raise PopupException(_('Cannot read table'), detail=e)
+
+
+def read_partition(request, database, table, partition_id):
+  db = dbms.get(request.user)
+  try:
+    partition = db.get_partition(database, table, int(partition_id))
+    url = reverse('beeswax:watch_query', args=[partition.id]) + '?context=table:%s:%s' % (table, database)
+    return redirect(url)
+  except Exception, e:
+    raise PopupException(_('Cannot read table'), detail=e)
 
 
 def load_table(request, database, table):
@@ -235,4 +249,4 @@ def describe_partitions(request, database, table):
           'url': reverse('catalog:describe_partitions', kwargs={'database': database, 'table': table})
         },
       ],
-      'table': table_obj, 'partitions': partitions, 'request': request})
+      'database': database, 'table': table_obj, 'partitions': partitions, 'request': request})

+ 5 - 1
apps/catalog/static/css/catalog.css

@@ -1,3 +1,7 @@
 .hueBreadcrumb {
   padding: 7px 14px;
-}
+}
+
+.sidebar-nav {
+  padding: 9px 0;
+}