From e998ff668299bd6f1ac6976b903cdb4f3261c48b Mon Sep 17 00:00:00 2001 From: wecharyu Date: Wed, 15 May 2024 10:43:25 +0000 Subject: [PATCH] fix tests --- .../apache/hadoop/hive/ql/metadata/PartitionTree.java | 5 ++--- .../hive/ql/metadata/SessionHiveMetaStoreClient.java | 6 +++--- .../hadoop/hive/metastore/HiveMetaStoreClient.java | 3 +++ .../apache/hadoop/hive/metastore/MetaStoreDirectSql.java | 6 ++++-- .../hadoop/hive/metastore/MetastoreDirectSqlUtils.java | 6 ------ .../org/apache/hadoop/hive/metastore/ObjectStore.java | 4 ++++ .../hadoop/hive/metastore/client/TestListPartitions.java | 9 ++++++--- 7 files changed, 22 insertions(+), 17 deletions(-) diff --git a/ql/src/java/org/apache/hadoop/hive/ql/metadata/PartitionTree.java b/ql/src/java/org/apache/hadoop/hive/ql/metadata/PartitionTree.java index ad94dfd114f7..da6d19cf3198 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/metadata/PartitionTree.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/metadata/PartitionTree.java @@ -36,7 +36,6 @@ import java.util.List; import java.util.Map; -import static org.apache.hadoop.hive.metastore.Warehouse.LOG; import static org.apache.hadoop.hive.metastore.Warehouse.makePartName; import static org.apache.hadoop.hive.metastore.utils.MetaStoreUtils.makePartNameMatcher; @@ -122,8 +121,8 @@ List addPartitions(List partitions, boolean ifNotExists) * {@link MetaStoreUtils#getPvals(List, Map)} */ List getPartitionsByPartitionVals(List partialPartVals) throws MetaException { - if (partialPartVals == null || partialPartVals.isEmpty()) { - throw new MetaException("Partition partial vals cannot be null or empty"); + if (MetaStoreUtils.arePartValsEmpty(partialPartVals)) { + return new ArrayList<>(parts.values()); } String partNameMatcher = makePartNameMatcher(tTable, partialPartVals, ".*"); List matchedPartitions = new ArrayList<>(); diff --git a/ql/src/java/org/apache/hadoop/hive/ql/metadata/SessionHiveMetaStoreClient.java b/ql/src/java/org/apache/hadoop/hive/ql/metadata/SessionHiveMetaStoreClient.java index d4b1f181869d..8f63e36294d1 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/metadata/SessionHiveMetaStoreClient.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/metadata/SessionHiveMetaStoreClient.java @@ -1139,7 +1139,7 @@ public List listPartitionsWithAuthInfo(String catName, String dbName, String tableName, List partialPvals, int maxParts, String userName, List groupNames) throws TException { org.apache.hadoop.hive.metastore.api.Table table = getTempTable(dbName, tableName); - if (table == null) { + if (table == null || partialPvals == null) { //(assume) not a temp table - Try underlying client return super.listPartitionsWithAuthInfo(catName, dbName, tableName, partialPvals, maxParts, userName, groupNames); @@ -1201,7 +1201,7 @@ public List listPartitionNames(String catName, String dbName, String tbl public List listPartitionNames(String catName, String dbName, String tblName, List partVals, int maxParts) throws TException { org.apache.hadoop.hive.metastore.api.Table table = getTempTable(dbName, tblName); - if (table == null) { + if (table == null || partVals == null) { return super.listPartitionNames(catName, dbName, tblName, partVals, maxParts); } TempTable tt = getPartitionedTempTable(table); @@ -1319,7 +1319,7 @@ public List listPartitions(String catName, String dbName, String tblN public List listPartitions(String catName, String dbName, String tblName, List partVals, int maxParts) throws TException { org.apache.hadoop.hive.metastore.api.Table table = getTempTable(dbName, tblName); - if (table == null) { + if (table == null || partVals == null) { return super.listPartitions(catName, dbName, tblName, partVals, maxParts); } TempTable tt = getPartitionedTempTable(table); diff --git a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java index ec7d8bec37d9..a8d2ae127b5c 100644 --- a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java +++ b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java @@ -3119,6 +3119,9 @@ public List listPartitionNames(String catName, String db_name, String tb protected List listPartitionNamesInternal(String catName, String db_name, String tbl_name, List part_vals, int max_parts) throws TException { + if (db_name == null || tbl_name == null || part_vals == null) { + throw new MetaException("Database name/Table name/partition values should not be null"); + } return client.get_partition_names_ps(prependCatalogToDbName(catName, db_name, conf), tbl_name, part_vals, shrinkMaxtoShort(max_parts)); } diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java index f3e3a9387c44..b08674f6805c 100644 --- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java +++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java @@ -1292,7 +1292,8 @@ public int getNumPartitionsViaSqlFilter(SqlFilterForPushdown filter) throws Meta } try (QueryWrapper query = new QueryWrapper(pm.newQuery("javax.jdo.query.SQL", queryText))) { - return MetastoreDirectSqlUtils.getCountOfQuery(query.getInnerQuery(), params); + query.setUnique(true); + return MetastoreDirectSqlUtils.extractSqlInt(executeWithArray(query.getInnerQuery(), params, queryText)); } } @@ -1314,7 +1315,8 @@ public int getNumPartitionsViaSqlPs(Table table, List partVals) throws M params[3] = partialName; try (QueryWrapper query = new QueryWrapper(pm.newQuery("javax.jdo.query.SQL", queryText))) { - return MetastoreDirectSqlUtils.getCountOfQuery(query.getInnerQuery(), params); + query.setUnique(true); + return MetastoreDirectSqlUtils.extractSqlInt(executeWithArray(query.getInnerQuery(), params, queryText)); } } diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetastoreDirectSqlUtils.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetastoreDirectSqlUtils.java index 1795c21b2ef4..8a608a030ee3 100644 --- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetastoreDirectSqlUtils.java +++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetastoreDirectSqlUtils.java @@ -609,10 +609,4 @@ public static void throwMetaOrRuntimeException(Exception e) throws MetaException throw new RuntimeException(e); } } - - static int getCountOfQuery(Query query, Object[] params) { - query.setUnique(true); - int sqlResult = MetastoreDirectSqlUtils.extractSqlInt(query.executeWithArray(params)); - return sqlResult; - } } diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java index bb0c15a2a51a..436b0f44a9e1 100644 --- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java +++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java @@ -3969,6 +3969,10 @@ protected List getJdoResult(GetHelper> ctx) @Override public List listPartitionNamesPs(String catName, String dbName, String tableName, List part_vals, short max_parts) throws MetaException, NoSuchObjectException { + if (MetaStoreUtils.arePartValsEmpty(part_vals)) { + return listPartitionNames(catName, dbName, tableName, max_parts); + } + List partitionNames = new ArrayList<>(); boolean success = false; diff --git a/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestListPartitions.java b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestListPartitions.java index be435030cbc2..47142220c6db 100644 --- a/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestListPartitions.java +++ b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestListPartitions.java @@ -1420,10 +1420,13 @@ public void testListPartitionNamesByValuesLowPartCount() throws Exception { Lists.newArrayList("yyyy", "mm", "dd")); } - @Test(expected = MetaException.class) + @Test public void testListPartitionNamesByValuesNoPartVals() throws Exception { - createTable4PartColsParts(client); - client.listPartitionNames(DB_NAME, TABLE_NAME, Lists.newArrayList(), (short)-1); + List> testValues = createTable4PartColsParts(client).testValues; + List partitionNames = client.listPartitionNames(DB_NAME, TABLE_NAME, + Lists.newArrayList(), (short)-1); + assertTrue(partitionNames.size() == 4); + assertCorrectPartitionNames(partitionNames, testValues, Lists.newArrayList("yyyy", "mm", "dd")); } @Test(expected = MetaException.class)