Prechádzať zdrojové kódy

[metastore] Remove the now non used static variables of the describe page

Romain Rigaux 10 rokov pred
rodič
commit
0f4d582

+ 10 - 25
apps/metastore/src/metastore/templates/describe_table.mako

@@ -272,17 +272,15 @@ ${ assist.assistPanel() }
             </h3>
             </h3>
             <div class="clearfix"></div>
             <div class="clearfix"></div>
 
 
-            <span data-bind="editable: comment, editableOptions: {enabled: true, placement: 'right', emptytext: 'Add a description...' }" class="editable editable-click editable-empty">Add a description...</span>
+            <span data-bind="editable: comment, editableOptions: {enabled: true, placement: 'right', emptytext: 'Add a description...' }" class="editable editable-click editable-empty">${ _('Add a description...') }</span>
 
 
             <ul class="nav nav-pills margin-top-30">
             <ul class="nav nav-pills margin-top-30">
               <li><a href="#overview" data-toggle="tab">${_('Overview')}</a></li>
               <li><a href="#overview" data-toggle="tab">${_('Overview')}</a></li>
               <li><a href="#columns" data-toggle="tab">${_('Columns')} (<span data-bind="text: columns().length"></span>)</a></li>
               <li><a href="#columns" data-toggle="tab">${_('Columns')} (<span data-bind="text: columns().length"></span>)</a></li>
               % if table.partition_keys:
               % if table.partition_keys:
-                <li><a href="#partitionColumns" data-toggle="tab">${_('Partition Columns')}</a></li>
-              % endif
-              % if sample is not None:
-                <li><a href="#sample" data-toggle="tab">${_('Sample')}</a></li>
+                <li><a href="#partitionColumns" data-toggle="tab">${_('Partition Columns')} (${ len(table.partition_keys) })</a></li>
               % endif
               % endif
+              <li><a href="#sample" data-toggle="tab">${_('Sample')}</a></li>
               <li><a href="#permissions" data-toggle="tab">${_('Permissions')}</a></li>
               <li><a href="#permissions" data-toggle="tab">${_('Permissions')}</a></li>
               <li><a href="#queries" data-toggle="tab">${_('Queries')}</a></li>
               <li><a href="#queries" data-toggle="tab">${_('Queries')}</a></li>
               <li><a href="#analysis" data-toggle="tab">${_('Analyse')}</a></li>
               <li><a href="#analysis" data-toggle="tab">${_('Analyse')}</a></li>
@@ -323,19 +321,15 @@ ${ assist.assistPanel() }
 
 
                 <div class="tile">
                 <div class="tile">
                   <h4>${ _('Sample') }</h4>
                   <h4>${ _('Sample') }</h4>
-                  % if sample:
                     <!-- ko with: samplesPreview -->
                     <!-- ko with: samplesPreview -->
-                    <!-- ko template: 'metastore-samples-table' --><!-- /ko -->
+                      <!-- ko template: 'metastore-samples-table' --><!-- /ko -->
                     <!-- /ko -->
                     <!-- /ko -->
                     <a class="pointer" data-bind="click: function() { $('li a[href=\'#sample\']').click(); }">${_('View more...')}</a>
                     <a class="pointer" data-bind="click: function() { $('li a[href=\'#sample\']').click(); }">${_('View more...')}</a>
-                  % else:
-                    ${ _('Table sampling took too long.') }
-                  % endif
                 </div>
                 </div>
 
 
                 % if table.partition_keys:
                 % if table.partition_keys:
                   <div class="tile">
                   <div class="tile">
-                    <h4>${ _('Partitions') }</h4>
+                    <h4>${ _('Partitions') } (${ len(table.partition_keys) })</h4>
                     ${ partition_column_table(table.partition_keys, "partitionTable", limit=3) }
                     ${ partition_column_table(table.partition_keys, "partitionTable", limit=3) }
                     <a class="pointer" data-bind="click: function() { $('li a[href=\'#partitionColumns\']').click(); }">${_('View more...')}</a>
                     <a class="pointer" data-bind="click: function() { $('li a[href=\'#partitionColumns\']').click(); }">${_('View more...')}</a>
                   </div>
                   </div>
@@ -354,20 +348,11 @@ ${ assist.assistPanel() }
                 </div>
                 </div>
               % endif
               % endif
 
 
-              % if sample is not None:
-                <div class="tab-pane" id="sample">
-                  % if error_message:
-                    <div class="alert alert-error">
-                      <h3>${_('Error!')}</h3>
-                      <pre>${ error_message }</pre>
-                    </div>
-                  % else:
-                    <!-- ko with: samples -->
-                    <!-- ko template: 'metastore-samples-table' --><!-- /ko -->
-                    <!-- /ko -->
-                  % endif
-                </div>
-              % endif
+              <div class="tab-pane" id="sample">
+                <!-- ko with: samples -->
+                <!-- ko template: 'metastore-samples-table' --><!-- /ko -->
+                <!-- /ko -->
+              </div>
 
 
               <div class="tab-pane" id="permissions">
               <div class="tab-pane" id="permissions">
                 ${ _('Not available') }
                 ${ _('Not available') }

+ 16 - 13
apps/metastore/src/metastore/views.py

@@ -213,9 +213,6 @@ def describe_table(request, database, table):
   query_server = get_query_server_config(app_name)
   query_server = get_query_server_config(app_name)
   db = dbms.get(request.user, query_server)
   db = dbms.get(request.user, query_server)
 
 
-  error_message = ''
-  table_data = ''
-
   try:
   try:
     table = db.get_table(database, table)
     table = db.get_table(database, table)
   except Exception, e:
   except Exception, e:
@@ -244,16 +241,25 @@ def describe_table(request, database, table):
         'stats': table.stats
         'stats': table.stats
     })
     })
 
 
-  try:
-    table_data = db.get_sample(database, table)
-  except Exception, ex:
-    error_message, logs = dbms.expand_exception(ex, db)
-
   renderable = "describe_table.mako"
   renderable = "describe_table.mako"
   if request.REQUEST.get("sample", "false") == "true":
   if request.REQUEST.get("sample", "false") == "true":
     renderable = "sample.mako"
     renderable = "sample.mako"
     if request.REQUEST.get("format", "html") == "json":
     if request.REQUEST.get("format", "html") == "json":
-      return JsonResponse({'status': 0, 'headers': table_data and table_data.cols(), 'rows': table_data and list(table_data.rows())})
+      response = {'status': -1, 'error_message': ''}
+      error_message = ''
+      table_data = ''      
+      try:
+        table_data = db.get_sample(database, table)
+        response.update({
+            'status': 0,
+            'headers': table_data and table_data.cols(),
+            'rows': table_data and list(table_data.rows())
+        })
+      except Exception, ex:
+        error_message, logs = dbms.expand_exception(ex, db)
+        response['error_message'] = error_message
+        
+      return JsonResponse(response)
 
 
   return render(renderable, request, {
   return render(renderable, request, {
     'breadcrumbs': [{
     'breadcrumbs': [{
@@ -265,12 +271,9 @@ def describe_table(request, database, table):
       },
       },
     ],
     ],
     'table': table,
     'table': table,
-    'partitions': partitions,
-    'sample': table_data,
-    'sample_rows': table_data and list(table_data.rows()),
-    'error_message': error_message,
     'database': database,
     'database': database,
     'has_write_access': has_write_access(request.user),
     'has_write_access': has_write_access(request.user),
+    'partitions': partitions
   })
   })