You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by th...@apache.org on 2014/05/30 09:29:48 UTC

svn commit: r1598478 - /hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java

Author: thejas
Date: Fri May 30 07:29:47 2014
New Revision: 1598478

URL: http://svn.apache.org/r1598478
Log:
HIVE-7130 : schematool is broken for minor version upgrades (eg 0.13.x) (Thejas Nair, reviewed by Ashutosh Chauhan)

Modified:
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java

Modified: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java?rev=1598478&r1=1598477&r2=1598478&view=diff
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java (original)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java Fri May 30 07:29:47 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;
+    }
   }
 
 }