فهرست منبع

HUE-2617 [metastore] Return partition results in reverse order by default

Jenny Kim 10 سال پیش
والد
کامیت
6be710f115

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

@@ -570,14 +570,11 @@ class HiveServer2Dbms(object):
     return self.client.close(handle)
 
 
-  def get_partitions(self, db_name, table, max_parts=None):
+  def get_partitions(self, db_name, table, max_parts=None, reverse_sort=True):
     if max_parts is None or max_parts > BROWSE_PARTITIONED_TABLE_LIMIT.get():
       max_parts = BROWSE_PARTITIONED_TABLE_LIMIT.get()
 
-    # DB name not supported in SHOW PARTITIONS
-    self.use(db_name)
-
-    return self.client.get_partitions(db_name, table.name, max_parts)
+    return self.client.get_partitions(db_name, table.name, max_parts, reverse_sort)
 
   def get_partition(self, db_name, table_name, partition_id):
     table = self.get_table(db_name, table_name)

+ 9 - 4
apps/beeswax/src/beeswax/server/hive_server2_lib.py

@@ -746,7 +746,7 @@ class HiveServerClient:
       return 'Server does not support GetLog()'
 
 
-  def get_partitions(self, database, table_name, max_parts):
+  def get_partitions(self, database, table_name, max_parts, reverse_sort=True):
     table = self.get_table(database, table_name)
 
     if max_parts is None or max_parts <= 0:
@@ -755,7 +755,12 @@ class HiveServerClient:
       max_rows = 1000 if max_parts <= 250 else max_parts
 
     partitionTable = self.execute_query_statement('SHOW PARTITIONS %s.%s' % (database, table_name), max_rows=max_rows)
-    return [PartitionValueCompatible(partition, table) for partition in partitionTable.rows()][-max_parts:]
+    partitions = [PartitionValueCompatible(partition, table) for partition in partitionTable.rows()][-max_parts:]
+
+    if reverse_sort:
+      partitions.reverse()
+
+    return partitions
 
 
   def _get_query_configuration(self, query):
@@ -975,8 +980,8 @@ class HiveServerClientCompatible(object):
   def get_partition(self, *args, **kwargs): raise NotImplementedError()
 
 
-  def get_partitions(self, database, table_name, max_parts):
-    return self._client.get_partitions(database, table_name, max_parts)
+  def get_partitions(self, database, table_name, max_parts, reverse_sort=True):
+    return self._client.get_partitions(database, table_name, max_parts, reverse_sort)
 
 
   def alter_partition(self, db_name, tbl_name, new_part): raise NotImplementedError()

+ 8 - 0
apps/beeswax/src/beeswax/test_base.py

@@ -370,6 +370,14 @@ class BeeswaxSampleProvider(object):
     cls._make_data_file(data_file % 2)
     cls._make_table(table_info['name'], CREATE_TABLE % table_info, data_file % 2)
 
+    # Insert additional partition data into "test_partitions" table
+    INSERT_PARTITION_DATA = """
+      INSERT INTO TABLE test_partitions
+      PARTITION(baz='baz_two', boom='boom_two')
+      SELECT foo, bar FROM test
+    """
+    make_query(cls.client, INSERT_PARTITION_DATA, wait=True, local=False)
+
     # Create a "test_utf8" table.
     table_info = dict(name='test_utf8', comment=cls.get_i18n_table_comment())
     cls._make_i18n_data_file(data_file % 3, 'utf-8')

+ 2 - 1
apps/metastore/src/metastore/tests.py

@@ -112,10 +112,11 @@ class TestMetastoreWithHadoop(BeeswaxSampleProvider):
 
   def test_describe_partitions(self):
     response = self.client.get("/metastore/table/default/test_partitions")
-    assert_true("Show Partitions (1)" in response.content, response.content)
+    assert_true("Show Partitions (2)" in response.content, response.content)
 
     response = self.client.get("/metastore/table/default/test_partitions/partitions", follow=True)
     assert_true("baz_one" in response.content)
+    assert_true("baz_two" in response.content)
     assert_true("boom_two" in response.content)
     # Breadcrumbs
     assert_true("default" in response.content)

+ 3 - 1
apps/metastore/src/metastore/views.py

@@ -269,7 +269,9 @@ def describe_partitions(request, database, table):
   if not table_obj.partition_keys:
     raise PopupException(_("Table '%(table)s' is not partitioned.") % {'table': table})
 
-  partitions = db.get_partitions(database, table_obj, max_parts=None)
+  reverse_sort = request.REQUEST.get("sort", "desc").lower() == "desc"
+
+  partitions = db.get_partitions(database, table_obj, max_parts=None, reverse_sort=reverse_sort)
 
   return render("describe_partitions.mako", request, {
     'breadcrumbs': [{