This is an automated email from the ASF dual-hosted git repository.

kgyrtkirk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/master by this push:
     new 9f9844d  HIVE-24975: Fix a bug in ValidWriteIdList comparison in 
TxnIdUtils (#2641) (Sourabh Goyal reviewed by Zoltan Haindrich)
9f9844d is described below

commit 9f9844dbc881e2a9267c259b8c04e7787f7fadc4
Author: Sourabh Goyal <soura...@cloudera.com>
AuthorDate: Thu Dec 9 01:21:08 2021 -0800

    HIVE-24975: Fix a bug in ValidWriteIdList comparison in TxnIdUtils (#2641) 
(Sourabh Goyal reviewed by Zoltan Haindrich)
---
 .../src/java/org/apache/hive/common/util/TxnIdUtils.java      |  2 +-
 .../src/test/org/apache/hive/common/util/TestTxnIdUtils.java  | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/storage-api/src/java/org/apache/hive/common/util/TxnIdUtils.java 
b/storage-api/src/java/org/apache/hive/common/util/TxnIdUtils.java
index bd972d4..7de7464 100644
--- a/storage-api/src/java/org/apache/hive/common/util/TxnIdUtils.java
+++ b/storage-api/src/java/org/apache/hive/common/util/TxnIdUtils.java
@@ -67,7 +67,7 @@ public class TxnIdUtils {
       }
     } else {
       if (b.getHighWatermark() != a.getInvalidWriteIds()[minLen] -1) {
-        return Long.signum(b.getHighWatermark() - 
(a.getInvalidWriteIds()[minLen] -1));
+        return Long.signum((a.getInvalidWriteIds()[minLen] - 1) - 
b.getHighWatermark());
       }
       if (allInvalidFrom(a.getInvalidWriteIds(), minLen, 
a.getHighWatermark())) {
         return 0;
diff --git 
a/storage-api/src/test/org/apache/hive/common/util/TestTxnIdUtils.java 
b/storage-api/src/test/org/apache/hive/common/util/TestTxnIdUtils.java
index ab5a472..1f646a3 100644
--- a/storage-api/src/test/org/apache/hive/common/util/TestTxnIdUtils.java
+++ b/storage-api/src/test/org/apache/hive/common/util/TestTxnIdUtils.java
@@ -19,6 +19,7 @@ package org.apache.hive.common.util;
 
 import java.util.BitSet;
 
+import org.apache.hadoop.hive.common.ValidWriteIdList;
 import org.apache.hadoop.hive.common.ValidReaderWriteIdList;
 import org.junit.Test;
 import static org.junit.Assert.assertEquals;
@@ -190,5 +191,15 @@ public class TestTxnIdUtils {
         new ValidReaderWriteIdList("default.table2", new long[] {8,10,11}, new 
BitSet(), 11)),
     -1);
 
+    ValidWriteIdList a =
+        new ValidReaderWriteIdList("default.test:1:1:1:");
+    ValidWriteIdList b =
+        new ValidReaderWriteIdList("default.test:1:9223372036854775807::");
+
+    // should return -1 since b is more recent
+    assertEquals(TxnIdUtils.compare(a, b), -1);
+
+    // should return 1 since b is more recent
+    assertEquals(TxnIdUtils.compare(b, a), 1);
   }
 }

Reply via email to