diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java b/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java index a8c02b4..22ba029 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java @@ -5596,12 +5596,11 @@ public UpdateMDatabaseURIRetVal updateMDatabaseURI(URI oldLoc, URI newLoc, boole } } - public class UpdateMStorageDescriptorTblPropURIRetVal { + public class UpdateTblPropURIRetVal { private List badRecords; private Map updateLocations; - UpdateMStorageDescriptorTblPropURIRetVal(List badRecords, - Map updateLocations) { + UpdateTblPropURIRetVal(List badRecords, Map updateLocations) { this.badRecords = badRecords; this.updateLocations = updateLocations; } @@ -5624,62 +5623,64 @@ public void setUpdateLocations(Map updateLocations) { } /** The following APIs - * - * - updateMStorageDescriptorTblPropURI - * - * is used by HiveMetaTool. This API **shouldn't** be exposed via Thrift. - * - */ - public UpdateMStorageDescriptorTblPropURIRetVal updateMStorageDescriptorTblPropURI(URI oldLoc, - URI newLoc, String tblPropKey, boolean isDryRun) { + * + * - updateMTblPropURI + * + * is used by HiveMetaTool. This API **shouldn't** be exposed via Thrift. + * + */ + public UpdateTblPropURIRetVal updateMTblPropURI(URI oldLoc, URI newLoc, String tblPropKey, + boolean isDryRun) { boolean committed = false; Map updateLocations = new HashMap(); List badRecords = new ArrayList(); - UpdateMStorageDescriptorTblPropURIRetVal retVal = null; + UpdateTblPropURIRetVal retVal = null; try { openTransaction(); - Query query = pm.newQuery(MStorageDescriptor.class); - List mSDSs = (List) query.execute(); - pm.retrieveAll(mSDSs); + Query query = pm.newQuery(MTable.class); + List mTbls = (List) query.execute(); + pm.retrieveAll(mTbls); - for(MStorageDescriptor mSDS:mSDSs) { + for (MTable mTbl : mTbls) { URI tablePropLocationURI = null; - if (mSDS.getParameters().containsKey(tblPropKey)) { - String tablePropLocation = mSDS.getParameters().get(tblPropKey); + if (mTbl.getParameters().containsKey(tblPropKey)) { + String tablePropLocation = mTbl.getParameters().get(tblPropKey); try { - tablePropLocationURI = new URI(tablePropLocation); - } catch (URISyntaxException e) { - badRecords.add(tablePropLocation); - } catch (NullPointerException e) { - badRecords.add(tablePropLocation); + tablePropLocationURI = new URI(tablePropLocation); + } catch (URISyntaxException e) { + badRecords.add(tablePropLocation); + } catch (NullPointerException e) { + badRecords.add(tablePropLocation); + } + // if tablePropKey that was passed in lead to a valid URI resolution, update it if + //parts of it match the old-NN-loc, else add to badRecords + if (tablePropLocationURI == null) { + badRecords.add(tablePropLocation); + } else { + if (shouldUpdateURI(tablePropLocationURI, oldLoc)) { + String tblPropLoc = mTbl.getParameters().get(tblPropKey).replaceAll(oldLoc.toString(), + newLoc.toString()); + updateLocations.put(tablePropLocationURI.toString(), tblPropLoc); + if (!isDryRun) { + Map parameters = mTbl.getParameters(); + parameters.remove(tblPropKey); + parameters.put(tblPropKey, tblPropLoc); + } } - // if tablePropKey that was passed in lead to a valid URI resolution, update it if - //parts of it match the old-NN-loc, else add to badRecords - if (tablePropLocationURI == null) { - badRecords.add(tablePropLocation); - } else { - if (shouldUpdateURI(tablePropLocationURI, oldLoc)) { - String tblPropLoc = mSDS.getParameters().get(tblPropKey).replaceAll(oldLoc.toString(), - newLoc.toString()); - updateLocations.put(tablePropLocationURI.toString(), tblPropLoc); - if (!isDryRun) { - mSDS.getParameters().put(tblPropKey, tblPropLoc); - } - } - } - } + } + } } committed = commitTransaction(); if (committed) { - retVal = new UpdateMStorageDescriptorTblPropURIRetVal(badRecords, updateLocations); + retVal = new UpdateTblPropURIRetVal(badRecords, updateLocations); } return retVal; - } finally { - if (!committed) { - rollbackTransaction(); - } - } + } finally { + if (!committed) { + rollbackTransaction(); + } + } } public class UpdateMStorageDescriptorTblURIRetVal { diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/tools/HiveMetaTool.java b/metastore/src/java/org/apache/hadoop/hive/metastore/tools/HiveMetaTool.java index 7dc5f44..bab44d5 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/tools/HiveMetaTool.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/tools/HiveMetaTool.java @@ -254,12 +254,12 @@ private void printDatabaseURIUpdateSummary(ObjectStore.UpdateMDatabaseURIRetVal } private void printTblPropURIUpdateSummary( - ObjectStore.UpdateMStorageDescriptorTblPropURIRetVal retVal, String tablePropKey, + ObjectStore.UpdateTblPropURIRetVal retVal, String tablePropKey, boolean isDryRun) { - String tblName = new String("SD_PARAMS"); + String tblName = new String("TABLE_PARAMS"); if (retVal == null) { - System.err.println("Encountered error while executing updateMStorageDescriptorTblPropURI - " + + System.err.println("Encountered error while executing updateMTblPropURI - " + "commit of JDO transaction failed. Failed to update FSRoot locations in " + "value field corresponding to" + tablePropKey + " in " + tblName + " table."); } else { @@ -334,11 +334,10 @@ public void updateFSRootLocation(URI oldURI, URI newURI, String serdePropKey, printTblURIUpdateSummary(updateTblURIRetVal, isDryRun); if (tablePropKey != null) { - System.out.println("Looking for value of " + tablePropKey + " key in SD_PARAMS table " + + System.out.println("Looking for value of " + tablePropKey + " key in TABLE_PARAMS table " + "to update.."); - ObjectStore.UpdateMStorageDescriptorTblPropURIRetVal updateTblPropURIRetVal = - objStore.updateMStorageDescriptorTblPropURI(oldURI, newURI, - tablePropKey, isDryRun); + ObjectStore.UpdateTblPropURIRetVal updateTblPropURIRetVal = + objStore.updateMTblPropURI(oldURI, newURI, tablePropKey, isDryRun); printTblPropURIUpdateSummary(updateTblPropURIRetVal, tablePropKey, isDryRun); }