diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java index 221b010..ea7a4f0 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java @@ -149,6 +149,8 @@ public void alterTable(RawStore msdb, Warehouse wh, String dbname, newt.getSd().setLocation(newTblLoc); oldTblLoc = oldt.getSd().getLocation(); moveData = true; + int partitionBatchSize = HiveConf.getIntVar(hiveConf, + HiveConf.ConfVars.METASTORE_BATCH_RETRIEVE_MAX); // check that destination does not exist otherwise we will be // overwriting data srcPath = new Path(oldTblLoc); @@ -177,23 +179,28 @@ public void alterTable(RawStore msdb, Warehouse wh, String dbname, + newt.getTableName()); } // also the location field in partition - List parts = msdb.getPartitions(dbname, name, -1); - for (Partition part : parts) { - String oldPartLoc = part.getSd().getLocation(); - Path oldPartLocPath = new Path(oldPartLoc); - String oldTblLocPath = new Path(oldTblLoc).toUri().getPath(); - String newTblLocPath = new Path(newTblLoc).toUri().getPath(); - if (oldPartLoc.contains(oldTblLocPath)) { - Path newPartLocPath = null; - URI oldUri = oldPartLocPath.toUri(); - String newPath = oldUri.getPath().replace(oldTblLocPath, - newTblLocPath); - - newPartLocPath = new Path(oldUri.getScheme(), - oldUri.getAuthority(), - newPath); - part.getSd().setLocation(newPartLocPath.toString()); - msdb.alterPartition(dbname, name, part.getValues(), part); + while(true) { + List parts = msdb.getPartitions(dbname, name, partitionBatchSize); + if (parts == null || parts.isEmpty()) { + break; + } + for (Partition part : parts) { + String oldPartLoc = part.getSd().getLocation(); + Path oldPartLocPath = new Path(oldPartLoc); + String oldTblLocPath = new Path(oldTblLoc).toUri().getPath(); + String newTblLocPath = new Path(newTblLoc).toUri().getPath(); + if (oldPartLoc.contains(oldTblLocPath)) { + Path newPartLocPath = null; + URI oldUri = oldPartLocPath.toUri(); + String newPath = oldUri.getPath().replace(oldTblLocPath, + newTblLocPath); + + newPartLocPath = new Path(oldUri.getScheme(), + oldUri.getAuthority(), + newPath); + part.getSd().setLocation(newPartLocPath.toString()); + msdb.alterPartition(dbname, name, part.getValues(), part); + } } } } else if (MetaStoreUtils.requireCalStats(hiveConf, null, null, newt) &&