diff --git standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index ecc464418df8f60b60a18e934400138f209cf51b..b9821475fd925c15442eeb8dd59e98175c01be96 100644 --- standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -4066,6 +4066,7 @@ private static boolean is_partition_spec_grouping_enabled(Table table) { List ret = null; Exception ex = null; try { + checkLimitNumberOfPartitionsByFilter(db_name, tbl_name, NO_FILTER_STRING, max_parts); ret = getMS().listPartitionNames(db_name, tbl_name, max_parts); } catch (Exception e) { ex = e; diff --git standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java index b3d99a1da591d52c5068a433bf8c3b8e42347082..d89badeb6ddf80a573f6c7a131bddec48586a54d 100644 --- standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java +++ standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java @@ -2731,6 +2731,9 @@ private PartitionValuesResponse getDistinctValuesForPartitionsNoTxn(String dbNam private List getPartitionNamesNoTxn(String dbName, String tableName, short max) { List pns = new ArrayList<>(); + if (max == 0) { + return pns; + } dbName = normalizeIdentifier(dbName); tableName = normalizeIdentifier(tableName); Query query = @@ -2739,6 +2742,7 @@ private PartitionValuesResponse getDistinctValuesForPartitionsNoTxn(String dbNam + "order by partitionName asc"); query.declareParameters("java.lang.String t1, java.lang.String t2"); query.setResult("partitionName"); + if (max > 0) { query.setRange(0, max); } diff --git standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestListPartitions.java standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestListPartitions.java index f4fa73beddf2f28ac0addcd6aaaef7d8dead16c9..0e004b7207c5632520dbf61a8e18ba4690d1dbb4 100644 --- standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestListPartitions.java +++ standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestListPartitions.java @@ -1040,18 +1040,15 @@ public void testListPartitionNames() throws Exception { assertCorrectPartitionNames(partitionNames, testValues.subList(0, 2), Lists.newArrayList("yyyy", "mm", "dd")); - - //TODO: surprisingly listPartitionNames returns everything when 0 parts are requested partitionNames = client.listPartitionNames(DB_NAME, TABLE_NAME, (short)0); - assertFalse(partitionNames.isEmpty()); - assertCorrectPartitionNames(partitionNames, testValues, Lists.newArrayList("yyyy", "mm", - "dd")); + assertTrue(partitionNames.isEmpty()); - //TODO: surprisingly listPartitionNames doesn't fail when >100 parts are requested - partitionNames = client.listPartitionNames(DB_NAME, TABLE_NAME, (short)101); - assertCorrectPartitionNames(partitionNames, testValues, Lists.newArrayList("yyyy", "mm", - "dd")); + } + @Test(expected = MetaException.class) + public void testListPartitionNamesHighMaxParts() throws Exception { + createTable4PartColsParts(client); + client.listPartitionNames(DB_NAME, TABLE_NAME, (short)101); } @Test(expected = NoSuchObjectException.class)