wecharyu commented on code in PR #4480:
URL: https://github.com/apache/hive/pull/4480#discussion_r1272407256
##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java:
##########
@@ -4368,167 +4367,104 @@ public AddPartitionsResult
add_partitions_req(AddPartitionsRequest request)
if (request.getParts().isEmpty()) {
return result;
}
+ String catName = request.isSetCatName() ? request.getCatName() :
getDefaultCatalog(conf);
+ String dbName = request.getDbName();
+ String tblName = request.getTblName();
+ startTableFunction("add_partitions_req", catName, dbName, tblName);
+
+ Exception ex = null;
try {
if (!request.isSetCatName()) {
- request.setCatName(getDefaultCatalog(conf));
+ request.setCatName(catName);
}
- // Make sure all of the partitions have the catalog set as well
- request.getParts().forEach(p -> {
- if (!p.isSetCatName()) {
- p.setCatName(getDefaultCatalog(conf));
- }
- });
- List<Partition> parts = add_partitions_core(getMS(),
request.getCatName(), request.getDbName(),
- request.getTblName(), request.getParts(), request.isIfNotExists());
+ // Make sure all the partitions have the catalog set as well
+ request.getParts().forEach(p -> p.setCatName(catName));
+ List<Partition> parts = add_partitions_core(getMS(),
+ catName, dbName, tblName, request.getParts(),
request.isIfNotExists());
if (request.isNeedResult()) {
result.setPartitions(parts);
}
} catch (Exception e) {
+ ex = e;
throw
handleException(e).throwIfInstance(TException.class).defaultMetaException();
+ } finally {
+ endFunction("add_partitions_req", ex == null, ex, tblName);
}
return result;
}
@Override
public int add_partitions(final List<Partition> parts) throws MetaException,
InvalidObjectException, AlreadyExistsException {
- startFunction("add_partition");
if (parts == null) {
throw new MetaException("Partition list cannot be null.");
}
if (parts.isEmpty()) {
return 0;
}
+ String catName = parts.get(0).isSetCatName() ? parts.get(0).getCatName() :
getDefaultCatalog(conf);
+ String dbName = parts.get(0).getDbName();
+ String tableName = parts.get(0).getTableName();
+ startTableFunction("add_partitions", catName, dbName, tableName);
Integer ret = null;
Exception ex = null;
try {
// Old API assumed all partitions belong to the same table; keep the
same assumption
if (!parts.get(0).isSetCatName()) {
- String defaultCat = getDefaultCatalog(conf);
- for (Partition p : parts) {
- p.setCatName(defaultCat);
- }
+ parts.forEach(p -> p.setCatName(catName));
}
- ret = add_partitions_core(getMS(), parts.get(0).getCatName(),
parts.get(0).getDbName(),
- parts.get(0).getTableName(), parts, false).size();
+ ret = add_partitions_core(getMS(), catName, dbName, tableName, parts,
false).size();
assert ret == parts.size();
} catch (Exception e) {
ex = e;
throw handleException(e)
.throwIfInstance(MetaException.class, InvalidObjectException.class,
AlreadyExistsException.class)
.defaultMetaException();
} finally {
- String tableName = parts.get(0).getTableName();
- endFunction("add_partition", ret != null, ex, tableName);
+ endFunction("add_partitions", ret != null, ex, tableName);
}
return ret;
}
@Override
public int add_partitions_pspec(final List<PartitionSpec> partSpecs)
throws TException {
- logAndAudit("add_partitions_pspec");
-
if (partSpecs.isEmpty()) {
return 0;
}
+ String catName = partSpecs.get(0).isSetCatName() ?
partSpecs.get(0).getCatName() : getDefaultCatalog(conf);
String dbName = partSpecs.get(0).getDbName();
String tableName = partSpecs.get(0).getTableName();
- // If the catalog name isn't set, we need to go through and set it.
- String catName;
- if (!partSpecs.get(0).isSetCatName()) {
- catName = getDefaultCatalog(conf);
- partSpecs.forEach(ps -> ps.setCatName(catName));
- } else {
- catName = partSpecs.get(0).getCatName();
- }
+ startTableFunction("add_partitions_pspec", catName, dbName, tableName);
- return add_partitions_pspec_core(getMS(), catName, dbName, tableName,
partSpecs, false);
- }
-
- private int add_partitions_pspec_core(RawStore ms, String catName, String
dbName,
- String tblName, List<PartitionSpec>
partSpecs,
- boolean ifNotExists)
- throws TException {
- boolean success = false;
- if (dbName == null || tblName == null) {
- throw new MetaException("The database and table name cannot be null.");
- }
Review Comment:
Make sense, move the check to the common add_partitions_core function.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]