hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hashut...@apache.org
Subject svn commit: r1590998 - in /hive/trunk/ql/src: java/org/apache/hadoop/hive/ql/lockmgr/HiveLockObject.java test/org/apache/hadoop/hive/ql/lockmgr/TestHiveLockObject.java
Date Tue, 29 Apr 2014 14:52:37 GMT
Author: hashutosh
Date: Tue Apr 29 14:52:37 2014
New Revision: 1590998

URL: http://svn.apache.org/r1590998
Log:
HIVE-6884 : HiveLockObject and enclosed HiveLockObjectData override equal() method but didn't
do so for hashcode() (Xuefu Zhang via Ashutosh Chauhan)

Added:
    hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/lockmgr/TestHiveLockObject.java
Modified:
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/HiveLockObject.java

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/HiveLockObject.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/HiveLockObject.java?rev=1590998&r1=1590997&r2=1590998&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/HiveLockObject.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/HiveLockObject.java Tue Apr 29
14:52:37 2014
@@ -20,6 +20,7 @@ package org.apache.hadoop.hive.ql.lockmg
 
 import java.util.Arrays;
 
+import org.apache.commons.lang.builder.HashCodeBuilder;
 import org.apache.hadoop.hive.ql.metadata.DummyPartition;
 import org.apache.hadoop.hive.ql.metadata.Partition;
 import org.apache.hadoop.hive.ql.metadata.Table;
@@ -121,6 +122,44 @@ public class HiveLockObject {
 
       return ret;
     }
+ 
+    @Override
+    public int hashCode() {
+      HashCodeBuilder builder = new HashCodeBuilder();
+
+      boolean queryId_present = queryId == null;
+      builder.append(queryId_present);
+      if (queryId_present) {
+        builder.append(queryId);
+      }
+
+      boolean lockTime_present = lockTime == null;
+      builder.append(lockTime);
+      if (lockTime_present) {
+        builder.append(lockTime);
+      }
+
+      boolean lockMode_present = lockMode == null;
+      builder.append(lockMode);
+      if (lockMode_present) {
+        builder.append(lockMode);
+      }
+
+      boolean queryStr_present = queryStr == null;
+      builder.append(queryStr);
+      if (queryStr_present) {
+        builder.append(queryStr);
+      }
+
+      boolean clienIp_present = clientIp == null;
+      builder.append(clientIp);
+      if (clienIp_present) {
+        builder.append(clientIp);
+      }
+
+      return builder.toHashCode();
+    }
+
   }
 
   /* user supplied data for that object */
@@ -216,6 +255,18 @@ public class HiveLockObject {
         tgt.getData() != null && data.equals(tgt.getData());
   }
 
+  @Override
+  public int hashCode() {
+    HashCodeBuilder builder = new HashCodeBuilder();
+    builder.append(pathNames);
+    boolean data_present = data == null;
+    builder.append(data_present);
+    if (data_present) {
+      builder.append(data);
+    }
+    return builder.toHashCode();
+  }
+
   private static String removeDelimiter(String in) {
     if (in == null) {
       return null;

Added: hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/lockmgr/TestHiveLockObject.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/lockmgr/TestHiveLockObject.java?rev=1590998&view=auto
==============================================================================
--- hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/lockmgr/TestHiveLockObject.java (added)
+++ hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/lockmgr/TestHiveLockObject.java Tue Apr
29 14:52:37 2014
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.lockmgr;
+
+import junit.framework.Assert;
+
+import org.apache.hadoop.hive.ql.lockmgr.HiveLockObject.HiveLockObjectData;
+import org.junit.Test;
+
+public class TestHiveLockObject {
+
+  @Test
+  public void testEqualsAndHashCode() {
+    HiveLockObjectData data1 = new HiveLockObjectData("ID1", "SHARED", "1997-07-01", "select
* from mytable");
+    HiveLockObjectData data2 = new HiveLockObjectData("ID1", "SHARED", "1997-07-01", "select
* from mytable");
+    Assert.assertEquals(data1, data2);
+    Assert.assertEquals(data1.hashCode(), data2.hashCode());
+
+    HiveLockObject obj1 = new HiveLockObject("mytable", data1);
+    HiveLockObject obj2 = new HiveLockObject("mytable", data2);
+    Assert.assertEquals(obj1, obj2);
+    Assert.assertEquals(obj1.hashCode(), obj2.hashCode());
+  }
+
+}



Mime
View raw message