Skip to content

Commit eb1c3b1

Browse files
HIVE-28956 : Implement DirectSql for alter table add column cascade command.
1 parent b9449b3 commit eb1c3b1

File tree

1 file changed

+33
-10
lines changed
  • standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore

1 file changed

+33
-10
lines changed

standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -410,21 +410,44 @@ public List<Void> run(List<Partition> input) throws Exception {
410410
if (cascade || retainOnColRemoval) {
411411
parts = msdb.getPartitions(catName, dbname, name, -1);
412412
for (Partition part : parts) {
413-
Partition oldPart = new Partition(part);
414413
List<FieldSchema> oldCols = part.getSd().getCols();
415414
part.getSd().setCols(newt.getSd().getCols());
416415
List<ColumnStatistics> colStats = updateOrGetPartitionColumnStats(msdb, catName, dbname, name,
417416
part.getValues(), oldCols, oldt, part, null, null);
418417
assert (colStats.isEmpty());
419-
Deadline.checkTimeout();
420-
if (cascade) {
421-
msdb.alterPartition(
422-
catName, dbname, name, part.getValues(), part, writeIdList);
423-
} else {
424-
// update changed properties (stats)
425-
oldPart.setParameters(part.getParameters());
426-
msdb.alterPartition(catName, dbname, name, part.getValues(), oldPart, writeIdList);
427-
}
418+
}
419+
String catalogName = catName;
420+
int partitionBatchSize = MetastoreConf.getIntVar(handler.getConf(),
421+
MetastoreConf.ConfVars.BATCH_RETRIEVE_MAX);
422+
if (cascade) {
423+
Batchable.runBatched(partitionBatchSize, parts, new Batchable<Partition, Void>() {
424+
@Override
425+
public List<Void> run(List<Partition> input) throws Exception {
426+
Deadline.checkTimeout();
427+
msdb.alterPartitions(catalogName, newDbName, newTblName,
428+
input.stream().map(Partition::getValues).collect(Collectors.toList()),
429+
input, newt.getWriteId(), writeIdList);
430+
return Collections.emptyList();
431+
}
432+
});
433+
} else {
434+
Batchable.runBatched(partitionBatchSize, parts, new Batchable<Partition, Void>() {
435+
@Override
436+
public List<Void> run(List<Partition> input) throws Exception {
437+
Deadline.checkTimeout();
438+
List<Partition> oldParts = new ArrayList<>(parts.size());
439+
// update changed properties (stats)
440+
for (Partition part : input) {
441+
Partition oldPart = new Partition(part);
442+
oldPart.setParameters(part.getParameters());
443+
oldParts.add(oldPart);
444+
}
445+
msdb.alterPartitions(catalogName, newDbName, newTblName,
446+
input.stream().map(Partition::getValues).collect(Collectors.toList()),
447+
oldParts, newt.getWriteId(), writeIdList);
448+
return Collections.emptyList();
449+
}
450+
});
428451
}
429452
} else {
430453
// clear all column stats to prevent incorract behaviour in case same column is reintroduced

0 commit comments

Comments
 (0)