You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by xu...@apache.org on 2015/10/28 13:11:27 UTC

[34/55] [abbrv] hive git commit: HIVE-12261 : schematool version info exit status should depend on compatibility, not equality (Thejas Nair, reviewed by Sushanth Sowmyan)

HIVE-12261 : schematool version info exit status should depend on compatibility, not equality (Thejas Nair, reviewed by Sushanth Sowmyan)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/1f9556d8
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/1f9556d8
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/1f9556d8

Branch: refs/heads/spark
Commit: 1f9556d843ae5bfaf0c701f4f7428dfabc127e7c
Parents: f415ce9
Author: Thejas Nair <th...@hortonworks.com>
Authored: Sun Oct 25 23:47:57 2015 -0700
Committer: Thejas Nair <th...@hortonworks.com>
Committed: Sun Oct 25 23:47:57 2015 -0700

----------------------------------------------------------------------
 .../org/apache/hive/beeline/HiveSchemaTool.java | 12 +++---
 .../hive/metastore/MetaStoreSchemaInfo.java     | 44 ++++++++++++++++++++
 2 files changed, 50 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/1f9556d8/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java
----------------------------------------------------------------------
diff --git a/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java b/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java
index 9e72a3a..6f0ba07 100644
--- a/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java
+++ b/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java
@@ -129,7 +129,7 @@ public class HiveSchemaTool {
     String dbVersion = getMetaStoreSchemaVersion(metastoreConn);
     System.out.println("Hive distribution version:\t " + hiveVersion);
     System.out.println("Metastore schema version:\t " + dbVersion);
-    assertSameVersion(hiveVersion, dbVersion);
+    assertCompatibleVersion(hiveVersion, dbVersion);
 
   }
 
@@ -185,15 +185,15 @@ public class HiveSchemaTool {
     String newSchemaVersion = getMetaStoreSchemaVersion(
         getConnectionToMetastore(false));
     // verify that the new version is added to schema
-    assertSameVersion(MetaStoreSchemaInfo.getHiveSchemaVersion(), newSchemaVersion);
+    assertCompatibleVersion(MetaStoreSchemaInfo.getHiveSchemaVersion(), newSchemaVersion);
 
   }
 
-  private void assertSameVersion(String hiveSchemaVersion, String dbSchemaVersion)
+  private void assertCompatibleVersion(String hiveSchemaVersion, String dbSchemaVersion)
       throws HiveMetaException {
-    if (!hiveSchemaVersion.equalsIgnoreCase(dbSchemaVersion)) {
-      throw new HiveMetaException("Expected schema version " + hiveSchemaVersion
-          + ", found version " + dbSchemaVersion);
+    if (!MetaStoreSchemaInfo.isVersionCompatible(hiveSchemaVersion, dbSchemaVersion)) {
+      throw new HiveMetaException("Metastore schema version is not compatible. Hive Version: "
+          + hiveSchemaVersion + ", Database Schema Version: " + dbSchemaVersion);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/hive/blob/1f9556d8/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java
----------------------------------------------------------------------
diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java b/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java
index d72267d..98798e8 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java
@@ -151,6 +151,10 @@ public class MetaStoreSchemaInfo {
 
   public static String getHiveSchemaVersion() {
     String hiveVersion = HiveVersionInfo.getShortVersion();
+    return getEquivalentVersion(hiveVersion);
+  }
+
+  private static String getEquivalentVersion(String hiveVersion) {
     // if there is an equivalent version, return that, else return this version
     String equivalentVersion = EQUIVALENT_VERSIONS.get(hiveVersion);
     if (equivalentVersion != null) {
@@ -160,4 +164,44 @@ public class MetaStoreSchemaInfo {
     }
   }
 
+  /**
+   * A dbVersion is compatible with hive version if it is greater or equal to
+   * the hive version. This is result of the db schema upgrade design principles
+   * followed in hive project.
+   *
+   * @param hiveVersion
+   *          version of hive software
+   * @param dbVersion
+   *          version of metastore rdbms schema
+   * @return true if versions are compatible
+   */
+  public static boolean isVersionCompatible(String hiveVersion, String dbVersion) {
+    hiveVersion = getEquivalentVersion(hiveVersion);
+    dbVersion = getEquivalentVersion(dbVersion);
+    if (hiveVersion.equals(dbVersion)) {
+      return true;
+    }
+    String[] hiveVerParts = hiveVersion.split("\\.");
+    String[] dbVerParts = dbVersion.split("\\.");
+    if (hiveVerParts.length != 3 || dbVerParts.length != 3) {
+      // these are non standard version numbers. can't perform the
+      // comparison on these, so assume that they are incompatible
+      return false;
+    }
+
+    for (int i = 0; i < dbVerParts.length; i++) {
+      Integer dbVerPart = Integer.valueOf(dbVerParts[i]);
+      Integer hiveVerPart = Integer.valueOf(hiveVerParts[i]);
+      if (dbVerPart > hiveVerPart) {
+        return true;
+      } else if (dbVerPart < hiveVerPart) {
+        return false;
+      } else {
+        continue; // compare next part
+      }
+    }
+
+    return true;
+  }
+
 }