[ 
https://issues.apache.org/jira/browse/HIVE-26062?focusedWorklogId=747243&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-747243
 ]

ASF GitHub Bot logged work on HIVE-26062:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 24/Mar/22 14:06
            Start Date: 24/Mar/22 14:06
    Worklog Time Spent: 10m 
      Work Description: 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-unsubscr...@hive.apache.org

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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 747243)
    Time Spent: 40m  (was: 0.5h)

> Make sure that running 4.0.0-alpha-2 above 4.0.0-alpha-1 HMS DB reports the 
> correct error
> -----------------------------------------------------------------------------------------
>
>                 Key: HIVE-26062
>                 URL: https://issues.apache.org/jira/browse/HIVE-26062
>             Project: Hive
>          Issue Type: Task
>            Reporter: Peter Vary
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> When comparing expected and actual HMS DB versions the code has problems with 
> parsing  {{alpha-1}}. We should make sure that the appropriate error message 
> is returned to the customer instead of a {{NumberFormatException}}.
> Currently we have this, and we might just want to return {{false}} if there 
> is no exact match:
> {code}
> java.lang.NumberFormatException: For input string: "0-alpha-1"
> at 
> java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
> at java.lang.Integer.parseInt(Integer.java:580)
> at java.lang.Integer.parseInt(Integer.java:615)
> at 
> org.apache.hadoop.hive.metastore.MetaStoreSchemaInfo.isVersionCompatible(MetaStoreSchemaInfo.java:210)
> at 
> org.apache.hadoop.hive.metastore.ObjectStore.checkSchema(ObjectStore.java:10870)
> at 
> org.apache.hadoop.hive.metastore.ObjectStore.verifySchema(ObjectStore.java:10839)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:498)
> at 
> org.apache.hadoop.hive.metastore.RawStoreProxy.invoke(RawStoreProxy.java:97)
> at com.sun.proxy.$Proxy28.verifySchema(Unknown Source)
> at 
> org.apache.hadoop.hive.metastore.HMSHandler.getMSForConf(HMSHandler.java:610)
> at org.apache.hadoop.hive.metastore.HMSHandler.getMS(HMSHandler.java:602)
> at 
> org.apache.hadoop.hive.metastore.HMSHandler.createDefaultDB(HMSHandler.java:686)
> {code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to