Skip to content

Commit

Permalink
revert null part_vals check in client
Browse files Browse the repository at this point in the history
  • Loading branch information
wecharyu committed May 14, 2024
1 parent 44ba9f6 commit 93058a7
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ List<Partition> addPartitions(List<Partition> partitions, boolean ifNotExists)
* {@link MetaStoreUtils#getPvals(List, Map)}
*/
List<Partition> getPartitionsByPartitionVals(List<String> partialPartVals) throws MetaException {
if (MetaStoreUtils.arePartValsEmpty(partialPartVals)) {
return new ArrayList<>(parts.values());
if (partialPartVals == null || partialPartVals.isEmpty()) {
throw new MetaException("Partition partial vals cannot be null or empty");
}
String partNameMatcher = makePartNameMatcher(tTable, partialPartVals, ".*");
List<Partition> matchedPartitions = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2245,8 +2245,8 @@ public List<Partition> listPartitions(String db_name, String tbl_name,
public List<Partition> listPartitions(String catName, String db_name, String tbl_name,
List<String> part_vals, int max_parts) throws TException {
// TODO should we add capabilities here as well as it returns Partition objects
if (db_name == null || tbl_name == null) {
throw new MetaException("Database name/Table name should not be null");
if (db_name == null || tbl_name == null || part_vals == null) {
throw new MetaException("Database name/Table name/partition values should not be null");
}
GetPartitionsPsWithAuthRequest req = createThriftPartitionsReq(GetPartitionsPsWithAuthRequest.class, conf);
req.setDbName(db_name);
Expand Down Expand Up @@ -2361,8 +2361,8 @@ public List<Partition> listPartitionsWithAuthInfo(String catName, String dbName,
protected List<Partition> listPartitionsWithAuthInfoInternal(String catName, String dbName, String tableName,
List<String> partialPvals, int maxParts, String userName, List<String> groupNames)
throws TException {
if (dbName == null || tableName == null) {
throw new MetaException("Database name/Table name should not be null");
if (dbName == null || tableName == null || partialPvals == null) {
throw new MetaException("Database name/Table name/partition values should not be null");
}
GetPartitionsPsWithAuthRequest req = createThriftPartitionsReq(GetPartitionsPsWithAuthRequest.class, conf);
req.setTblName(tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,9 @@ public int getNumPartitionsViaSqlFilter(SqlFilterForPushdown filter) throws Meta
params[i + 3] = filter.params.get(i);
}

return MetastoreDirectSqlUtils.getCountOfQuery(pm, queryText, params);
try (QueryWrapper query = new QueryWrapper(pm.newQuery("javax.jdo.query.SQL", queryText))) {
return MetastoreDirectSqlUtils.getCountOfQuery(query.getInnerQuery(), params);
}
}

public int getNumPartitionsViaSqlPs(Table table, List<String> partVals) throws MetaException {
Expand All @@ -1311,7 +1313,9 @@ public int getNumPartitionsViaSqlPs(Table table, List<String> partVals) throws M
params[2] = table.getCatName();
params[3] = partialName;

return MetastoreDirectSqlUtils.getCountOfQuery(pm, queryText, params);
try (QueryWrapper query = new QueryWrapper(pm.newQuery("javax.jdo.query.SQL", queryText))) {
return MetastoreDirectSqlUtils.getCountOfQuery(query.getInnerQuery(), params);
}
}

private static String trimCommaList(StringBuilder sb) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,15 +610,9 @@ public static void throwMetaOrRuntimeException(Exception e) throws MetaException
}
}

static int getCountOfQuery(PersistenceManager pm, String queryText, Object[] params) {
boolean doTrace = LOG.isDebugEnabled();
long start = doTrace ? System.nanoTime() : 0;
try (QueryWrapper query = new QueryWrapper(pm.newQuery("javax.jdo.query.SQL", queryText))) {
query.setUnique(true);
int sqlResult = MetastoreDirectSqlUtils.extractSqlInt(query.executeWithArray(params));
long queryTime = doTrace ? System.nanoTime() : 0;
MetastoreDirectSqlUtils.timingTrace(doTrace, queryText, start, queryTime);
return sqlResult;
}
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 @@ -3824,7 +3824,17 @@ protected Integer getSqlResult(GetHelper<Integer> ctx) throws MetaException {
@Override
protected Integer getJdoResult(GetHelper<Integer> ctx)
throws MetaException, NoSuchObjectException, InvalidObjectException {
return getNumPartitionsViaOrmPs(ctx.getTable(), partVals);
// size is known since it contains dbName, catName, tblName and partialRegex pattern
Map<String, String> params = new HashMap<>(4);
String filter = getJDOFilterStrForPartitionVals(ctx.getTable(), partVals, params);
try (QueryWrapper query = new QueryWrapper(pm.newQuery(
"select count(partitionName) from org.apache.hadoop.hive.metastore.model.MPartition"))) {
query.setFilter(filter);
query.declareParameters(makeParameterDeclarationString(params));
Long result = (Long) query.executeWithMap(params);

return result.intValue();
}
}
}.run(true);
}
Expand Down Expand Up @@ -3926,20 +3936,6 @@ public List<Partition> listPartitionsPsWithAuth(String catName, String db_name,
return partitions;
}

private Integer getNumPartitionsViaOrmPs(Table table, List<String> partVals) throws MetaException {
// size is known since it contains dbName, catName, tblName and partialRegex pattern
Map<String, String> params = new HashMap<>(4);
String filter = getJDOFilterStrForPartitionVals(table, partVals, params);
try (QueryWrapper query = new QueryWrapper(pm.newQuery(
"select count(partitionName) from org.apache.hadoop.hive.metastore.model.MPartition"))) {
query.setFilter(filter);
query.declareParameters(makeParameterDeclarationString(params));
Long result = (Long) query.executeWithMap(params);

return result.intValue();
}
}

private List<Partition> getPartitionsByPs(String catName, String dbName,
String tblName, GetPartitionsArgs args)
throws MetaException, NoSuchObjectException {
Expand Down Expand Up @@ -3973,10 +3969,6 @@ 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 @@ -459,13 +459,10 @@ public void testListPartitionsByValuesNullTblName() throws Exception {
client.listPartitions(DB_NAME, null, Lists.newArrayList("1999"), (short)-1);
}

@Test
@Test(expected = MetaException.class)
public void testListPartitionsByValuesNullValues() throws Exception {
createTable3PartCols1Part(client);
List<Partition> partitions = client.listPartitions(DB_NAME, TABLE_NAME,
(List<String>)null, (short)-1);
assertEquals(1, partitions.size());
assertPartitionsHaveCorrectParams(partitions);
client.listPartitions(DB_NAME, TABLE_NAME, (List<String>)null, (short)-1);
}


Expand Down Expand Up @@ -746,7 +743,7 @@ public void testListPartitionsWithAuthByValues() throws Exception {
public void testListPartitionsWithAuthByValuesNoVals() throws Exception {
List<List<String>> partValues = createTable4PartColsPartsAuthOn(client).testValues;
List<Partition> partitions = client.listPartitionsWithAuthInfo(DB_NAME, TABLE_NAME, Lists
.newArrayList(), (short)-1, "", Lists.newArrayList());
.newArrayList(), (short)-1, "", Lists.newArrayList());
assertEquals(4, partitions.size());
assertPartitionsHaveCorrectValues(partitions, partValues);
assertPartitionsHaveCorrectParams(partitions);
Expand Down Expand Up @@ -840,14 +837,11 @@ public void testListPartitionsWithAuthByValuesNullTblName() throws Exception {
}
}

@Test
@Test(expected = MetaException.class)
public void testListPartitionsWithAuthByValuesNullValues() throws Exception {
List<List<String>> partValues = createTable4PartColsParts(client).testValues;
List<Partition> partitions = client.listPartitionsWithAuthInfo(DB_NAME, TABLE_NAME,
(List<String>)null, (short)-1, "", Lists.newArrayList());
assertEquals(4, partitions.size());
assertPartitionsHaveCorrectValues(partitions, partValues);
assertPartitionsHaveCorrectParams(partitions);
createTable4PartColsParts(client);
client.listPartitionsWithAuthInfo(DB_NAME, TABLE_NAME, (List<String>)null,
(short)-1, "", Lists.newArrayList());
}

@Test
Expand Down Expand Up @@ -1426,12 +1420,10 @@ public void testListPartitionNamesByValuesLowPartCount() throws Exception {
Lists.newArrayList("yyyy", "mm", "dd"));
}

@Test
@Test(expected = MetaException.class)
public void testListPartitionNamesByValuesNoPartVals() throws Exception {
createTable4PartColsParts(client);
List<String> partNames = client.listPartitionNames(DB_NAME, TABLE_NAME,
Lists.newArrayList(), (short)-1);
assertEquals(4, partNames.size());
client.listPartitionNames(DB_NAME, TABLE_NAME, Lists.newArrayList(), (short)-1);
}

@Test(expected = MetaException.class)
Expand Down Expand Up @@ -1486,12 +1478,10 @@ public void testListPartitionNamesByValuesNullTblName() throws Exception {
}
}

@Test
@Test(expected = MetaException.class)
public void testListPartitionNamesByValuesNullValues() throws Exception {
createTable4PartColsParts(client);
List<String> partNames = client.listPartitionNames(DB_NAME, TABLE_NAME,
(List<String>)null, (short)-1);
assertEquals(4, partNames.size());
client.listPartitionNames(DB_NAME, TABLE_NAME, (List<String>)null, (short)-1);
}


Expand Down

0 comments on commit 93058a7

Please sign in to comment.