Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wecharyu committed May 15, 2024
1 parent 93058a7 commit e998ff6
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -122,8 +121,8 @@ List<Partition> addPartitions(List<Partition> partitions, boolean ifNotExists)
* {@link MetaStoreUtils#getPvals(List, Map)}
*/
List<Partition> getPartitionsByPartitionVals(List<String> 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<Partition> matchedPartitions = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ public List<Partition> listPartitionsWithAuthInfo(String catName, String dbName,
String tableName, List<String> partialPvals, int maxParts, String userName,
List<String> 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);
Expand Down Expand Up @@ -1201,7 +1201,7 @@ public List<String> listPartitionNames(String catName, String dbName, String tbl
public List<String> listPartitionNames(String catName, String dbName, String tblName,
List<String> 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);
Expand Down Expand Up @@ -1319,7 +1319,7 @@ public List<Partition> listPartitions(String catName, String dbName, String tblN
public List<Partition> listPartitions(String catName, String dbName, String tblName,
List<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3119,6 +3119,9 @@ public List<String> listPartitionNames(String catName, String db_name, String tb

protected List<String> listPartitionNamesInternal(String catName, String db_name, String tbl_name,
List<String> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand All @@ -1314,7 +1315,8 @@ public int getNumPartitionsViaSqlPs(Table table, List<String> 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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3969,6 +3969,10 @@ protected List<Partition> getJdoResult(GetHelper<List<Partition>> ctx)
@Override
public List<String> listPartitionNamesPs(String catName, String dbName, String tableName,
List<String> part_vals, short max_parts) throws MetaException, NoSuchObjectException {
if (MetaStoreUtils.arePartValsEmpty(part_vals)) {
return listPartitionNames(catName, dbName, tableName, max_parts);
}

List<String> partitionNames = new ArrayList<>();
boolean success = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<String>> testValues = createTable4PartColsParts(client).testValues;
List<String> 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)
Expand Down

0 comments on commit e998ff6

Please sign in to comment.