Author: khorgath Date: Mon Jun 2 18:55:48 2014 New Revision: 1599305 URL: http://svn.apache.org/r1599305 Log: HIVE-7130 : schematool is broken for minor version upgrades (eg 0.13.x) (Thejas Nair, reviewed by Ashutosh Chauhan)
Modified: hive/branches/branch-0.13/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java Modified: hive/branches/branch-0.13/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java URL: http://svn.apache.org/viewvc/hive/branches/branch-0.13/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java?rev=1599305&r1=1599304&r2=1599305&view=diff ============================================================================== --- hive/branches/branch-0.13/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java (original) +++ hive/branches/branch-0.13/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java Mon Jun 2 18:55:48 2014 @@ -24,10 +24,13 @@ import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Map; import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hive.common.util.HiveVersionInfo; +import com.google.common.collect.ImmutableMap; + public class MetaStoreSchemaInfo { private static String SQL_FILE_EXTENSION=".sql"; @@ -39,6 +42,11 @@ public class MetaStoreSchemaInfo { private final HiveConf hiveConf; private final String hiveHome; + // Minor version upgrades often don't change schema. So they are equivalent to a version + // that has a corresponding schema. eg "0.13.1" is equivalent to "0.13.0" + private static final Map<String, String> EQUIVALENT_VERSIONS = + ImmutableMap.of("0.13.1", "0.13.0"); + public MetaStoreSchemaInfo(String hiveHome, HiveConf hiveConf, String dbType) throws HiveMetaException { this.hiveHome = hiveHome; this.dbType = dbType; @@ -130,9 +138,15 @@ public class MetaStoreSchemaInfo { return UPGRADE_FILE_PREFIX + fileVersion + "." + dbType + SQL_FILE_EXTENSION; } - // Current hive version, in majorVersion.minorVersion.changeVersion format public static String getHiveSchemaVersion() { - return HiveVersionInfo.getShortVersion(); + String hiveVersion = HiveVersionInfo.getShortVersion(); + // if there is an equivalent version, return that, else return this version + String equivalentVersion = EQUIVALENT_VERSIONS.get(hiveVersion); + if (equivalentVersion != null) { + return equivalentVersion; + } else { + return hiveVersion; + } } }