瀏覽代碼

HUE-6831 [metastore] Editing view comments should use ALTER VIEW instead of TABLE

Ying Chen 8 年之前
父節點
當前提交
4c6e5af

+ 1 - 0
apps/beeswax/src/beeswax/api.py

@@ -130,6 +130,7 @@ def _autocomplete(db, database=None, table=None, column=None, nested=None):
       response['support_updates'] = table.is_impala_only
       response['columns'] = [column.name for column in table.cols]
       response['extended_columns'] = cols_extended
+      response['is_view'] = table.is_view
       response['partition_keys'] = [{'name': part.name, 'type': part.type} for part in table.partition_keys]
     else:
       col = db.get_column(database, table, column)

+ 9 - 1
apps/beeswax/src/beeswax/server/dbms.py

@@ -24,6 +24,7 @@ from django.utils.encoding import force_unicode
 from django.utils.translation import ugettext as _
 
 from desktop.lib.django_util import format_preserving_redirect
+from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.parameterization import substitute_variables
 from desktop.models import Cluster, IMPALAUI
 from filebrowser.views import location_to_url
@@ -225,7 +226,14 @@ class HiveServer2Dbms(object):
 
 
   def alter_table(self, database, table_name, new_table_name=None, comment=None, tblproperties=None):
-    hql = 'ALTER TABLE `%s`.`%s`' % (database, table_name)
+    table_obj = self.get_table(database, table_name)
+    if table_obj is None:
+      raise PopupException(_("Failed to find the table: %s") % table_name)
+
+    if table_obj.is_view:
+      hql = 'ALTER VIEW `%s`.`%s`' % (database, table_name)
+    else:
+      hql = 'ALTER TABLE `%s`.`%s`' % (database, table_name)
 
     if new_table_name:
       table_name = new_table_name

+ 2 - 0
apps/metastore/src/metastore/static/metastore/js/metastore.model.js

@@ -384,6 +384,7 @@ var MetastoreTable = (function () {
     self.sourceType = options.sourceType;
     self.name = options.name;
     self.type = options.type;
+    self.isView = ko.observable(false);
 
     self.optimizerStats = ko.observable();
     self.optimizerDetails = ko.observable();
@@ -479,6 +480,7 @@ var MetastoreTable = (function () {
         fields: [],
         successCallback: function (data) {
           self.loadingColumns(false);
+          self.isView(data.is_view);
           self.columns($.map(data.extended_columns, function (column) {
             return new MetastoreColumn({
               extendedColumn: column,

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

@@ -155,11 +155,16 @@ ${ components.menubar(is_embeddable) }
           <!-- /ko -->
           <td>
             % if has_write_access:
+              <!-- ko ifnot: table.isView() -->
               <div class="show-inactive-on-hover">
               <a class="inactive-action pointer toggle-editable" title="${ _('Edit the comment') }"><i class="fa fa-pencil"></i></a>
               <span data-bind="editable: comment, editableOptions: {enabled: true, type: 'wysihtml5', toggle: 'manual', skipNewLines: true, toggleElement: '.toggle-editable', placement: 'left', placeholder: '${ _ko('Add a comment...') }', emptytext: '${ _ko('Add a comment...') }', inputclass: 'input-xlarge'}">
                 ${ _('Add a comment...') }</span>
               </div>
+              <!-- /ko -->
+              <!-- ko if: table.isView() -->
+                <span data-bind="text: comment"></span>
+              <!-- /ko -->
             % else:
               <span data-bind="text: comment"></span>
             % endif