You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2022/03/24 14:06:43 UTC

[GitHub] [hive] pvary commented on a change in pull request #3138: HIVE-26062: Make sure that running 4.0.0-alpha-2 above 4.0.0-alpha-1 …

pvary commented on a change in pull request #3138:
URL: https://github.com/apache/hive/pull/3138#discussion_r834346677



##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java
##########
@@ -205,19 +206,33 @@ public boolean isVersionCompatible(String hiveVersion, String dbVersion) {
       return false;
     }
 
-    for (int i = 0; i < dbVerParts.length; i++) {
-      int dbVerPart = Integer.parseInt(dbVerParts[i]);
-      int hiveVerPart = Integer.parseInt(hiveVerParts[i]);
-      if (dbVerPart > hiveVerPart) {
-        return true;
-      } else if (dbVerPart < hiveVerPart) {
-        return false;
-      } else {
-        continue; // compare next part
+    hiveVerParts = hiveVersion.split("\\.|-");
+    dbVerParts = dbVersion.split("\\.|-");
+
+    int i = 0;
+    for (; i < Math.min(hiveVerParts.length, dbVerParts.length); i++) {
+      int compare = compareVersion(dbVerParts[i], hiveVerParts[i]);
+      if (compare != 0) {
+        return compare > 0;
       }
     }
 
-    return true;
+    return i == dbVerParts.length;
+  }
+
+  private int compareVersion(String dbVerPart, String hiveVerPart) {
+    if (dbVerPart.equals(hiveVerPart)) {
+      return 0;
+    }
+    boolean isDbVerNum = NumberUtils.isNumber(dbVerPart);
+    boolean isHiveVerNum = NumberUtils.isNumber(hiveVerPart);
+    if (isDbVerNum && isHiveVerNum) {
+      return Integer.parseInt(dbVerPart) - Integer.parseInt(hiveVerPart);
+    } else if (!isDbVerNum && !isHiveVerNum) {
+      return dbVerPart.compareTo(hiveVerPart);

Review comment:
       This might be unnecessary as we have already compared `dbVerPart` to `hiveVerPart` in the first line of the method




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org