Pārlūkot izejas kodu

[metastore] Fix alter table and column URL patterns and fix alter_column test

Jenny Kim 10 gadi atpakaļ
vecāks
revīzija
971514d

+ 2 - 2
apps/metastore/src/metastore/urls.py

@@ -27,7 +27,7 @@ urlpatterns = patterns('metastore.views',
   url(r'^tables/(?P<database>\w+)?$', 'show_tables', name='show_tables'),
   url(r'^tables/drop/(?P<database>\w+)$', 'drop_table', name='drop_table'),
   url(r'^table/(?P<database>\w+)/(?P<table>\w+)$', 'describe_table', name='describe_table'),
-  url(r'^table/(?P<database>\w+)/(?P<table>\w+)/alter', 'alter_table', name='alter_table'),
+  url(r'^table/(?P<database>\w+)/(?P<table>\w+)/alter$', 'alter_table', name='alter_table'),
   url(r'^table/(?P<database>\w+)/(?P<table>\w+)/metadata$', 'get_table_metadata', name='get_table_metadata'),
   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'),
@@ -36,5 +36,5 @@ urlpatterns = patterns('metastore.views',
   url(r'^table/(?P<database>\w+)/(?P<table>\w+)/partitions/(?P<partition_spec>.+?)/read$', 'read_partition', name='read_partition'),
   url(r'^table/(?P<database>\w+)/(?P<table>\w+)/partitions/(?P<partition_spec>.+?)/browse$', 'browse_partition', name='browse_partition'),
   url(r'^table/(?P<database>\w+)/(?P<table>\w+)/partitions/drop$', 'drop_partition', name='drop_partition'),
-  url(r'^table/(?P<database>\w+)/(?P<table>\w+)/alter_column', 'alter_column', name='alter_column'),
+  url(r'^table/(?P<database>\w+)/(?P<table>\w+)/alter_column$', 'alter_column', name='alter_column'),
 )

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

@@ -297,21 +297,25 @@ def alter_column(request, database, table):
   db = dbms.get(request.user)
   response = {'status': -1, 'data': ''}
   try:
-    column = request.POST.get('column')
-    col = db.get_column(database, table, column)
-    if col:
-      new_column_name = request.POST.get('new_column_name', col.name)
-      new_column_type = request.POST.get('new_column_type', col.type)
+    column = request.POST.get('column', None)
+
+    if column is None:
+      raise PopupException(_('alter_column requires a column parameter'))
+
+    column_obj = db.get_column(database, table, column)
+    if column_obj:
+      new_column_name = request.POST.get('new_column_name', column_obj.name)
+      new_column_type = request.POST.get('new_column_type', column_obj.type)
       comment = request.POST.get('comment', None)
       partition_spec = request.POST.get('partition_spec', None)
 
-      column = db.alter_column(database, table, column, new_column_name, new_column_type, comment=comment, partition_spec=partition_spec)
+      column_obj = db.alter_column(database, table, column, new_column_name, new_column_type, comment=comment, partition_spec=partition_spec)
 
       response['status'] = 0
       response['data'] = {
-        'name': column.name,
-        'type': column.type,
-        'comment': column.comment
+        'name': column_obj.name,
+        'type': column_obj.type,
+        'comment': column_obj.comment
       }
     else:
       raise PopupException(_('Column `%s`.`%s` `%s` not found') % (database, table, column))