use of java.util.NavigableSet in project hbase by apache.
the class ProtobufUtil method toGet.
/**
* Create a protocol buffer Get based on a client Get.
*
* @param get the client Get
* @return a protocol buffer Get
* @throws IOException
*/
public static ClientProtos.Get toGet(final Get get) throws IOException {
ClientProtos.Get.Builder builder = ClientProtos.Get.newBuilder();
builder.setRow(UnsafeByteOperations.unsafeWrap(get.getRow()));
builder.setCacheBlocks(get.getCacheBlocks());
builder.setMaxVersions(get.getMaxVersions());
if (get.getFilter() != null) {
builder.setFilter(ProtobufUtil.toFilter(get.getFilter()));
}
for (Entry<byte[], TimeRange> cftr : get.getColumnFamilyTimeRange().entrySet()) {
HBaseProtos.ColumnFamilyTimeRange.Builder b = HBaseProtos.ColumnFamilyTimeRange.newBuilder();
b.setColumnFamily(UnsafeByteOperations.unsafeWrap(cftr.getKey()));
b.setTimeRange(timeRangeToProto(cftr.getValue()));
builder.addCfTimeRange(b);
}
TimeRange timeRange = get.getTimeRange();
if (!timeRange.isAllTime()) {
HBaseProtos.TimeRange.Builder timeRangeBuilder = HBaseProtos.TimeRange.newBuilder();
timeRangeBuilder.setFrom(timeRange.getMin());
timeRangeBuilder.setTo(timeRange.getMax());
builder.setTimeRange(timeRangeBuilder.build());
}
Map<String, byte[]> attributes = get.getAttributesMap();
if (!attributes.isEmpty()) {
NameBytesPair.Builder attributeBuilder = NameBytesPair.newBuilder();
for (Map.Entry<String, byte[]> attribute : attributes.entrySet()) {
attributeBuilder.setName(attribute.getKey());
attributeBuilder.setValue(UnsafeByteOperations.unsafeWrap(attribute.getValue()));
builder.addAttribute(attributeBuilder.build());
}
}
if (get.hasFamilies()) {
Column.Builder columnBuilder = Column.newBuilder();
Map<byte[], NavigableSet<byte[]>> families = get.getFamilyMap();
for (Map.Entry<byte[], NavigableSet<byte[]>> family : families.entrySet()) {
NavigableSet<byte[]> qualifiers = family.getValue();
columnBuilder.setFamily(UnsafeByteOperations.unsafeWrap(family.getKey()));
columnBuilder.clearQualifier();
if (qualifiers != null && qualifiers.size() > 0) {
for (byte[] qualifier : qualifiers) {
columnBuilder.addQualifier(UnsafeByteOperations.unsafeWrap(qualifier));
}
}
builder.addColumn(columnBuilder.build());
}
}
if (get.getMaxResultsPerColumnFamily() >= 0) {
builder.setStoreLimit(get.getMaxResultsPerColumnFamily());
}
if (get.getRowOffsetPerColumnFamily() > 0) {
builder.setStoreOffset(get.getRowOffsetPerColumnFamily());
}
if (get.isCheckExistenceOnly()) {
builder.setExistenceOnly(true);
}
if (get.getConsistency() != null && get.getConsistency() != Consistency.STRONG) {
builder.setConsistency(toConsistency(get.getConsistency()));
}
Boolean loadColumnFamiliesOnDemand = get.getLoadColumnFamiliesOnDemandValue();
if (loadColumnFamiliesOnDemand != null) {
builder.setLoadColumnFamiliesOnDemand(loadColumnFamiliesOnDemand);
}
return builder.build();
}
use of java.util.NavigableSet in project hbase by apache.
the class ProtobufUtil method toGet.
/**
* Create a protocol buffer Get based on a client Get.
*
* @param get the client Get
* @return a protocol buffer Get
* @throws IOException
*/
public static ClientProtos.Get toGet(final Get get) throws IOException {
ClientProtos.Get.Builder builder = ClientProtos.Get.newBuilder();
builder.setRow(ByteStringer.wrap(get.getRow()));
builder.setCacheBlocks(get.getCacheBlocks());
builder.setMaxVersions(get.getMaxVersions());
if (get.getFilter() != null) {
builder.setFilter(ProtobufUtil.toFilter(get.getFilter()));
}
for (Entry<byte[], TimeRange> cftr : get.getColumnFamilyTimeRange().entrySet()) {
HBaseProtos.ColumnFamilyTimeRange.Builder b = HBaseProtos.ColumnFamilyTimeRange.newBuilder();
b.setColumnFamily(ByteStringer.wrap(cftr.getKey()));
b.setTimeRange(timeRangeToProto(cftr.getValue()));
builder.addCfTimeRange(b);
}
TimeRange timeRange = get.getTimeRange();
if (!timeRange.isAllTime()) {
HBaseProtos.TimeRange.Builder timeRangeBuilder = HBaseProtos.TimeRange.newBuilder();
timeRangeBuilder.setFrom(timeRange.getMin());
timeRangeBuilder.setTo(timeRange.getMax());
builder.setTimeRange(timeRangeBuilder.build());
}
Map<String, byte[]> attributes = get.getAttributesMap();
if (!attributes.isEmpty()) {
NameBytesPair.Builder attributeBuilder = NameBytesPair.newBuilder();
for (Map.Entry<String, byte[]> attribute : attributes.entrySet()) {
attributeBuilder.setName(attribute.getKey());
attributeBuilder.setValue(ByteStringer.wrap(attribute.getValue()));
builder.addAttribute(attributeBuilder.build());
}
}
if (get.hasFamilies()) {
Column.Builder columnBuilder = Column.newBuilder();
Map<byte[], NavigableSet<byte[]>> families = get.getFamilyMap();
for (Map.Entry<byte[], NavigableSet<byte[]>> family : families.entrySet()) {
NavigableSet<byte[]> qualifiers = family.getValue();
columnBuilder.setFamily(ByteStringer.wrap(family.getKey()));
columnBuilder.clearQualifier();
if (qualifiers != null && qualifiers.size() > 0) {
for (byte[] qualifier : qualifiers) {
columnBuilder.addQualifier(ByteStringer.wrap(qualifier));
}
}
builder.addColumn(columnBuilder.build());
}
}
if (get.getMaxResultsPerColumnFamily() >= 0) {
builder.setStoreLimit(get.getMaxResultsPerColumnFamily());
}
if (get.getRowOffsetPerColumnFamily() > 0) {
builder.setStoreOffset(get.getRowOffsetPerColumnFamily());
}
if (get.isCheckExistenceOnly()) {
builder.setExistenceOnly(true);
}
if (get.getConsistency() != null && get.getConsistency() != Consistency.STRONG) {
builder.setConsistency(toConsistency(get.getConsistency()));
}
Boolean loadColumnFamiliesOnDemand = get.getLoadColumnFamiliesOnDemandValue();
if (loadColumnFamiliesOnDemand != null) {
builder.setLoadColumnFamiliesOnDemand(loadColumnFamiliesOnDemand);
}
return builder.build();
}
use of java.util.NavigableSet in project hbase by apache.
the class TestSerialization method testGet.
/*
* TODO
@Test public void testPut() throws Exception{
byte[] row = "row".getBytes();
byte[] fam = "fam".getBytes();
byte[] qf1 = "qf1".getBytes();
byte[] qf2 = "qf2".getBytes();
byte[] qf3 = "qf3".getBytes();
byte[] qf4 = "qf4".getBytes();
byte[] qf5 = "qf5".getBytes();
byte[] qf6 = "qf6".getBytes();
byte[] qf7 = "qf7".getBytes();
byte[] qf8 = "qf8".getBytes();
long ts = System.currentTimeMillis();
byte[] val = "val".getBytes();
Put put = new Put(row);
put.setWriteToWAL(false);
put.add(fam, qf1, ts, val);
put.add(fam, qf2, ts, val);
put.add(fam, qf3, ts, val);
put.add(fam, qf4, ts, val);
put.add(fam, qf5, ts, val);
put.add(fam, qf6, ts, val);
put.add(fam, qf7, ts, val);
put.add(fam, qf8, ts, val);
byte[] sb = Writables.getBytes(put);
Put desPut = (Put)Writables.getWritable(sb, new Put());
//Timing test
// long start = System.nanoTime();
// desPut = (Put)Writables.getWritable(sb, new Put());
// long stop = System.nanoTime();
// System.out.println("timer " +(stop-start));
assertTrue(Bytes.equals(put.getRow(), desPut.getRow()));
List<KeyValue> list = null;
List<KeyValue> desList = null;
for(Map.Entry<byte[], List<KeyValue>> entry : put.getFamilyMap().entrySet()){
assertTrue(desPut.getFamilyMap().containsKey(entry.getKey()));
list = entry.getValue();
desList = desPut.getFamilyMap().get(entry.getKey());
for(int i=0; i<list.size(); i++){
assertTrue(list.get(i).equals(desList.get(i)));
}
}
}
@Test public void testPut2() throws Exception{
byte[] row = "testAbort,,1243116656250".getBytes();
byte[] fam = "historian".getBytes();
byte[] qf1 = "creation".getBytes();
long ts = 9223372036854775807L;
byte[] val = "dont-care".getBytes();
Put put = new Put(row);
put.add(fam, qf1, ts, val);
byte[] sb = Writables.getBytes(put);
Put desPut = (Put)Writables.getWritable(sb, new Put());
assertTrue(Bytes.equals(put.getRow(), desPut.getRow()));
List<KeyValue> list = null;
List<KeyValue> desList = null;
for(Map.Entry<byte[], List<KeyValue>> entry : put.getFamilyMap().entrySet()){
assertTrue(desPut.getFamilyMap().containsKey(entry.getKey()));
list = entry.getValue();
desList = desPut.getFamilyMap().get(entry.getKey());
for(int i=0; i<list.size(); i++){
assertTrue(list.get(i).equals(desList.get(i)));
}
}
}
@Test public void testDelete() throws Exception{
byte[] row = "row".getBytes();
byte[] fam = "fam".getBytes();
byte[] qf1 = "qf1".getBytes();
long ts = System.currentTimeMillis();
Delete delete = new Delete(row);
delete.deleteColumn(fam, qf1, ts);
byte[] sb = Writables.getBytes(delete);
Delete desDelete = (Delete)Writables.getWritable(sb, new Delete());
assertTrue(Bytes.equals(delete.getRow(), desDelete.getRow()));
List<KeyValue> list = null;
List<KeyValue> desList = null;
for(Map.Entry<byte[], List<KeyValue>> entry :
delete.getFamilyMap().entrySet()){
assertTrue(desDelete.getFamilyMap().containsKey(entry.getKey()));
list = entry.getValue();
desList = desDelete.getFamilyMap().get(entry.getKey());
for(int i=0; i<list.size(); i++){
assertTrue(list.get(i).equals(desList.get(i)));
}
}
}
*/
@Test
public void testGet() throws Exception {
byte[] row = "row".getBytes();
byte[] fam = "fam".getBytes();
byte[] qf1 = "qf1".getBytes();
long ts = System.currentTimeMillis();
int maxVersions = 2;
Get get = new Get(row);
get.addColumn(fam, qf1);
get.setTimeRange(ts, ts + 1);
get.setMaxVersions(maxVersions);
ClientProtos.Get getProto = ProtobufUtil.toGet(get);
Get desGet = ProtobufUtil.toGet(getProto);
assertTrue(Bytes.equals(get.getRow(), desGet.getRow()));
Set<byte[]> set = null;
Set<byte[]> desSet = null;
for (Map.Entry<byte[], NavigableSet<byte[]>> entry : get.getFamilyMap().entrySet()) {
assertTrue(desGet.getFamilyMap().containsKey(entry.getKey()));
set = entry.getValue();
desSet = desGet.getFamilyMap().get(entry.getKey());
for (byte[] qualifier : set) {
assertTrue(desSet.contains(qualifier));
}
}
assertEquals(get.getMaxVersions(), desGet.getMaxVersions());
TimeRange tr = get.getTimeRange();
TimeRange desTr = desGet.getTimeRange();
assertEquals(tr.getMax(), desTr.getMax());
assertEquals(tr.getMin(), desTr.getMin());
}
use of java.util.NavigableSet in project mapdb by jankotek.
the class ConcurrentSkipListSetTest method testIteratorRemove.
/**
* iterator.remove removes current element
*/
public void testIteratorRemove() {
final NavigableSet q = emptySet();
q.add(new Integer(2));
q.add(new Integer(1));
q.add(new Integer(3));
Iterator it = q.iterator();
it.next();
it.remove();
it = q.iterator();
assertEquals(it.next(), new Integer(2));
assertEquals(it.next(), new Integer(3));
assertFalse(it.hasNext());
}
use of java.util.NavigableSet in project mapdb by jankotek.
the class ConcurrentSkipListSetTest method testAddAll1.
/**
* addAll(null) throws NPE
*/
public void testAddAll1() {
NavigableSet q = emptySet();
try {
q.addAll(null);
shouldThrow();
} catch (NullPointerException success) {
}
}
Aggregations