@@ -410,21 +410,44 @@ public List<Void> run(List<Partition> input) throws Exception {
410
410
if (cascade || retainOnColRemoval ) {
411
411
parts = msdb .getPartitions (catName , dbname , name , -1 );
412
412
for (Partition part : parts ) {
413
- Partition oldPart = new Partition (part );
414
413
List <FieldSchema > oldCols = part .getSd ().getCols ();
415
414
part .getSd ().setCols (newt .getSd ().getCols ());
416
415
List <ColumnStatistics > colStats = updateOrGetPartitionColumnStats (msdb , catName , dbname , name ,
417
416
part .getValues (), oldCols , oldt , part , null , null );
418
417
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
+ });
428
451
}
429
452
} else {
430
453
// clear all column stats to prevent incorract behaviour in case same column is reintroduced
0 commit comments