You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by te...@apache.org on 2012/05/23 05:42:05 UTC

svn commit: r1341741 - in /hbase/branches/0.92: CHANGES.txt src/main/java/org/apache/hadoop/hbase/client/Put.java src/test/java/org/apache/hadoop/hbase/client/TestPutDotHas.java

Author: tedyu
Date: Wed May 23 03:42:05 2012
New Revision: 1341741

URL: http://svn.apache.org/viewvc?rev=1341741&view=rev
Log:
HBASE-6047 Put.has() can't determine result correctly (Alex Newman)

Added:
    hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/client/TestPutDotHas.java
Modified:
    hbase/branches/0.92/CHANGES.txt
    hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/client/Put.java

Modified: hbase/branches/0.92/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/CHANGES.txt?rev=1341741&r1=1341740&r2=1341741&view=diff
==============================================================================
--- hbase/branches/0.92/CHANGES.txt (original)
+++ hbase/branches/0.92/CHANGES.txt Wed May 23 03:42:05 2012
@@ -71,6 +71,7 @@ Release 0.92.2 - Unreleased
                (Derek Wollenstein)
    HBASE-5757  TableInputFormat should handle as many errors as possible (Jan Lukavsky)
    HBASE-6061  Fix ACL "Admin" Table inconsistent permission check (Matteo Bertozzi)
+   HBASE-6047  Put.has() can't determine result correctly (Alex Newman)
 
   IMPROVEMENTS
    HBASE-5592  Make it easier to get a table from shell (Ben West)

Modified: hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/client/Put.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/client/Put.java?rev=1341741&r1=1341740&r2=1341741&view=diff
==============================================================================
--- hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/client/Put.java (original)
+++ hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/client/Put.java Wed May 23 03:42:05 2012
@@ -252,8 +252,8 @@ public class Put extends Mutation
    * @return returns true if the given family, qualifier timestamp and value
    * already has an existing KeyValue object in the family map.
    */
-  private boolean has(byte [] family, byte [] qualifier, long ts, byte [] value,
-      boolean ignoreTS, boolean ignoreValue) {
+  private boolean has(byte[] family, byte[] qualifier, long ts, byte[] value,
+                      boolean ignoreTS, boolean ignoreValue) {
     List<KeyValue> list = getKeyValueList(family);
     if (list.size() == 0) {
       return false;
@@ -264,20 +264,32 @@ public class Put extends Mutation
     // F T => 2
     // F F => 1
     if (!ignoreTS && !ignoreValue) {
-      KeyValue kv = createPutKeyValue(family, qualifier, ts, value);
-      return (list.contains(kv));
-    } else if (ignoreValue) {
-      for (KeyValue kv: list) {
+      for (KeyValue kv : list) {
+        if (Arrays.equals(kv.getFamily(), family) &&
+            Arrays.equals(kv.getQualifier(), qualifier) &&
+            Arrays.equals(kv.getValue(), value) &&
+            kv.getTimestamp() == ts) {
+          return true;
+        }
+      }
+    } else if (ignoreValue && !ignoreTS) {
+      for (KeyValue kv : list) {
         if (Arrays.equals(kv.getFamily(), family) && Arrays.equals(kv.getQualifier(), qualifier)
             && kv.getTimestamp() == ts) {
           return true;
         }
       }
+    } else if (!ignoreValue && ignoreTS) {
+      for (KeyValue kv : list) {
+        if (Arrays.equals(kv.getFamily(), family) && Arrays.equals(kv.getQualifier(), qualifier)
+            && Arrays.equals(kv.getValue(), value)) {
+          return true;
+        }
+      }
     } else {
-      // ignoreTS is always true
-      for (KeyValue kv: list) {
-      if (Arrays.equals(kv.getFamily(), family) && Arrays.equals(kv.getQualifier(), qualifier)
-              && Arrays.equals(kv.getValue(), value)) {
+      for (KeyValue kv : list) {
+        if (Arrays.equals(kv.getFamily(), family) &&
+            Arrays.equals(kv.getQualifier(), qualifier)) {
           return true;
         }
       }

Added: hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/client/TestPutDotHas.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/client/TestPutDotHas.java?rev=1341741&view=auto
==============================================================================
--- hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/client/TestPutDotHas.java (added)
+++ hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/client/TestPutDotHas.java Wed May 23 03:42:05 2012
@@ -0,0 +1,74 @@
+/*
+ * 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.hbase.client;
+
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Addresses HBASE-6047
+ * We test put.has call with all of its polymorphic magic
+ */
+public class TestPutDotHas {
+
+  public static final byte[] ROW_01 = Bytes.toBytes("row-01");
+  public static final byte[] QUALIFIER_01 = Bytes.toBytes("qualifier-01");
+  public static final byte[] VALUE_01 = Bytes.toBytes("value-01");
+  public static final byte[] FAMILY_01 = Bytes.toBytes("family-01");
+  public static final long TS = 1234567L;
+  public Put put = new Put(ROW_01);
+
+  @Before
+  public void setUp() {
+    put.add(FAMILY_01, QUALIFIER_01, TS, VALUE_01);
+  }
+
+  @Test
+  public void testHasIgnoreValueIgnoreTS() {
+    Assert.assertTrue(put.has(FAMILY_01, QUALIFIER_01));
+    Assert.assertFalse(put.has(QUALIFIER_01, FAMILY_01));
+  }
+
+  @Test
+  public void testHasIgnoreValue() {
+    Assert.assertTrue(put.has(FAMILY_01, QUALIFIER_01, TS));
+    Assert.assertFalse(put.has(FAMILY_01, QUALIFIER_01, TS + 1));
+  }
+
+  @Test
+  public void testHasIgnoreTS() {
+    Assert.assertTrue(put.has(FAMILY_01, QUALIFIER_01, VALUE_01));
+    Assert.assertFalse(put.has(FAMILY_01, VALUE_01, QUALIFIER_01));
+  }
+
+  @Test
+  public void testHas() {
+    Assert.assertTrue(put.has(FAMILY_01, QUALIFIER_01, TS, VALUE_01));
+    // Bad TS
+    Assert.assertFalse(put.has(FAMILY_01, QUALIFIER_01, TS + 1, VALUE_01));
+    // Bad Value
+    Assert.assertFalse(put.has(FAMILY_01, QUALIFIER_01, TS, QUALIFIER_01));
+    // Bad Family
+    Assert.assertFalse(put.has(QUALIFIER_01, QUALIFIER_01, TS, VALUE_01));
+    // Bad Qual
+    Assert.assertFalse(put.has(FAMILY_01, FAMILY_01, TS, VALUE_01));
+  }
+}