Skip to content

Commit

Permalink
reduce a call of getMTable()
Browse files Browse the repository at this point in the history
  • Loading branch information
wecharyu committed Dec 22, 2023
1 parent 209ec76 commit 14de002
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5857,8 +5857,6 @@ private void alter_partition_core(String catName, String db_name, String tbl_nam
oldPart = alterHandler.alterPartition(getMS(), wh, catName, db_name, tbl_name,
part_vals, new_part, envContext, this, validWriteIds);

// Only fetch the table if we actually have a listener

if (!listeners.isEmpty()) {
MetaStoreListenerNotifier.notifyEvent(listeners,
EventType.ALTER_PARTITION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
import org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege;
import org.apache.hadoop.hive.metastore.model.MPartitionColumnStatistics;
import org.apache.hadoop.hive.metastore.model.MPartitionPrivilege;
import org.apache.hadoop.hive.metastore.model.MTable;
import org.apache.hadoop.hive.metastore.model.MTableColumnStatistics;
import org.apache.hadoop.hive.metastore.model.MWMResourcePlan;
import org.apache.hadoop.hive.metastore.parser.ExpressionTree;
Expand Down Expand Up @@ -547,14 +548,14 @@ public void addPartitions(List<MPartition> parts, List<List<MPartitionPrivilege>
* @return
* @throws MetaException
*/
public List<Partition> alterPartitions(Table table, List<String> partNames,
List<Partition> newParts, String queryWriteIdList) throws MetaException {
public List<Partition> alterPartitions(MTable table, List<String> partNames,
List<Partition> newParts, String queryWriteIdList) throws MetaException {
List<Object[]> rows = Batchable.runBatched(batchSize, partNames, new Batchable<String, Object[]>() {
@Override
public List<Object[]> run(List<String> input) throws Exception {
String filter = "" + PARTITIONS + ".\"PART_NAME\" in (" + makeParams(input.size()) + ")";
List<String> columns = Arrays.asList("\"PART_ID\"", "\"PART_NAME\"", "\"SD_ID\"", "\"WRITE_ID\"");
return getPartitionFieldsViaSqlFilter(table.getCatName(), table.getDbName(),
return getPartitionFieldsViaSqlFilter(table.getDatabase().getCatalogName(), table.getDatabase().getName(),
table.getTableName(), columns, filter, input, Collections.emptyList(), null);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5273,7 +5273,7 @@ public List<Partition> alterPartitions(String catName, String dbName, String tbl
try {
openTransaction();

Table table = ensureGetTable(catName, dbName, tblName);
MTable table = ensureGetMTable(catName, dbName, tblName);
// Validate new parts: StorageDescriptor and SerDeInfo must be set in Partition.
if (!TableType.VIRTUAL_VIEW.name().equals(table.getTableType())) {
for (Partition newPart : newParts) {
Expand All @@ -5286,9 +5286,10 @@ public List<Partition> alterPartitions(String catName, String dbName, String tbl
newParts.forEach(newPart -> newPart.setWriteId(writeId));
}

List<FieldSchema> partCols = convertToFieldSchemas(table.getPartitionKeys());
List<String> partNames = new ArrayList<>();
for (List<String> partVal : part_vals) {
partNames.add(Warehouse.makePartName(table.getPartitionKeys(), partVal));
partNames.add(Warehouse.makePartName(partCols, partVal));
}

results = new GetListHelper<Partition>(catName, dbName, tblName, true, true) {
Expand All @@ -5301,7 +5302,7 @@ protected List<Partition> getSqlResult(GetHelper<List<Partition>> ctx)
@Override
protected List<Partition> getJdoResult(GetHelper<List<Partition>> ctx)
throws MetaException, InvalidObjectException {
return alterPartitionsViaJdo(catName, dbName, tblName, partNames, newParts, queryWriteIdList);
return alterPartitionsViaJdo(table, partNames, newParts, queryWriteIdList);
}
}.run(false);

Expand All @@ -5318,12 +5319,12 @@ protected List<Partition> getJdoResult(GetHelper<List<Partition>> ctx)
return results;
}

private List<Partition> alterPartitionsViaJdo(String catName, String dbName, String tblName,
List<String> partNames, List<Partition> newParts, String queryWriteIdList)
private List<Partition> alterPartitionsViaJdo(MTable table, List<String> partNames,
List<Partition> newParts, String queryWriteIdList)
throws MetaException, InvalidObjectException {

MTable table = getMTable(catName, dbName, tblName);

String catName = table.getDatabase().getCatalogName();
String dbName = table.getDatabase().getName();
String tblName = table.getTableName();
List<Partition> results = new ArrayList<>(newParts.size());
List<MPartition> mPartitionList;

Expand Down

0 comments on commit 14de002

Please sign in to comment.