HBASE-7114 Increment does not extend Mutation but probably should
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1450931 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
21eda243ad
commit
8046661cd9
|
@ -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;
|
||||
|
@ -132,6 +134,29 @@ public class Increment extends Mutation implements Comparable<Row> {
|
|||
return !this.familyMap.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue