Abyss-lord commented on code in PR #6951:
URL: https://github.com/apache/gravitino/pull/6951#discussion_r2045827610


##########
clients/client-python/tests/unittests/test_gravitino_version.py:
##########
@@ -81,6 +81,12 @@ def test_version_compare(self):
 
         self.assertGreater(version1, version2)
 
+        # version1.minor < version2.minor and version1.patch > version.patch
+        version1 = GravitinoVersion(VersionDTO("0.6.1", "2023-01-01", 
"1234567"))
+        version2 = GravitinoVersion(VersionDTO("0.7.0", "2023-01-01", 
"1234567"))
+
+        self.assertFalse(version1 > version2)

Review Comment:
   Plz add more test cases, preferably positive ones like 
`self.assertTrue(version2 > version1)`



##########
clients/client-python/gravitino/client/gravitino_version.py:
##########
@@ -61,12 +61,13 @@ def __gt__(self, other) -> bool:
             raise GravitinoRuntimeException(
                 f"{GravitinoVersion.__name__} can't compare with 
{other.__class__.__name__}"
             )
-        if self.major > other.major:
-            return True
-        if self.minor > other.minor:
-            return True
-        if self.patch > other.patch:
-            return True
+        version_cmp = [(self.major, other.major), (self.minor, other.minor), 
(self.patch, other.patch)]
+        for (a, b) in version_cmp:
+            if a > b:
+                return True
+            if a < b:
+                return False
+        # self, other is the same

Review Comment:
   No need to use for loop, just `return (self.major, self.minor, self.patch) > 
(other.major, other.minor, other.patch)`
   A simple test:
   ```python
   def generate_tuple():
       return (0, random.randint(0, 9), random.randint(0, 9))
   
   
   for i in range(10):
       version1 = generate_tuple()
       version2 = generate_tuple()
       flg = ">" if version1 > version2 else "<"
   
       print(f"{version1} {flg} {version2}")
   ```
   result:
   ```
   (0, 3, 9) > (0, 0, 7)
   (0, 1, 3) < (0, 1, 4)
   (0, 6, 6) > (0, 4, 7)
   (0, 9, 8) > (0, 7, 1)
   (0, 1, 3) < (0, 9, 8)
   (0, 6, 4) > (0, 4, 4)
   (0, 9, 2) < (0, 9, 4)
   (0, 0, 5) < (0, 6, 9)
   (0, 8, 3) > (0, 3, 5)
   (0, 1, 2) < (0, 2, 0)
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to