You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2013/02/27 20:20:55 UTC
svn commit: r1450931 - in /hbase/trunk/hbase-client/src:
main/java/org/apache/hadoop/hbase/client/Increment.java
test/java/org/apache/hadoop/hbase/client/TestIncrement.java
Author: stack
Date: Wed Feb 27 19:20:54 2013
New Revision: 1450931
URL: http://svn.apache.org/r1450931
Log:
HBASE-7114 Increment does not extend Mutation but probably should
Added:
hbase/trunk/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestIncrement.java
Modified:
hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Increment.java
Modified: hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Increment.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Increment.java?rev=1450931&r1=1450930&r2=1450931&view=diff
==============================================================================
--- hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Increment.java (original)
+++ hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Increment.java Wed Feb 27 19:20:54 2013
@@ -22,6 +22,8 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import java.util.NavigableMap;
+import java.util.TreeMap;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
@@ -133,6 +135,29 @@ public class Increment extends Mutation
}
/**
+ * Before 0.95, when you called {@link Increment#getFamilyMap()}}, you got back
+ * a map of families to a list of Longs. Now, {@link #getFamilyMap()} returns
+ * families by list of Cells. This method has been added so you can have the
+ * old behavior.
+ * @return Map of families to a Map of qualifers and their Long increments.
+ * @since 0.95.0
+ */
+ public Map<byte[], NavigableMap<byte [], Long>> getFamilyMapOfLongs() {
+ NavigableMap<byte[], List<? extends Cell>> map = super.getFamilyMap();
+ Map<byte [], NavigableMap<byte[], Long>> results =
+ new TreeMap<byte[], NavigableMap<byte [], Long>>(Bytes.BYTES_COMPARATOR);
+ for (Map.Entry<byte [], List<? extends Cell>> entry: map.entrySet()) {
+ NavigableMap<byte [], Long> longs = new TreeMap<byte [], Long>(Bytes.BYTES_COMPARATOR);
+ for (Cell cell: entry.getValue()) {
+ KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
+ longs.put(kv.getQualifier(), Bytes.toLong(kv.getValue()));
+ }
+ results.put(entry.getKey(), longs);
+ }
+ return results;
+ }
+
+ /**
* @return String
*/
@Override
Added: hbase/trunk/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestIncrement.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestIncrement.java?rev=1450931&view=auto
==============================================================================
--- hbase/trunk/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestIncrement.java (added)
+++ hbase/trunk/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestIncrement.java Wed Feb 27 19:20:54 2013
@@ -0,0 +1,51 @@
+/**
+ * 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 static org.junit.Assert.assertEquals;
+
+import java.util.Map;
+import java.util.NavigableMap;
+
+import org.apache.hadoop.hbase.SmallTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+@Category(SmallTests.class)
+public class TestIncrement {
+ @Test
+ public void test() {
+ final long expected = 13;
+ Increment inc = new Increment(new byte [] {'r'});
+ int total = 0;
+ for (int i = 0; i < 2; i++) {
+ byte [] bytes = Bytes.toBytes(i);
+ inc.addColumn(bytes, bytes, expected);
+ total++;
+ }
+ Map<byte[], NavigableMap<byte [], Long>> familyMapOfLongs = inc.getFamilyMapOfLongs();
+ int found = 0;
+ for (Map.Entry<byte [], NavigableMap<byte [], Long>> entry: familyMapOfLongs.entrySet()) {
+ for (Map.Entry<byte [], Long> e: entry.getValue().entrySet()) {
+ assertEquals(expected, e.getValue().longValue());
+ found++;
+ }
+ }
+ assertEquals(total, found);
+ }
+}
\ No newline at end of file