hbase-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Saiph Kappa <saiph.ka...@gmail.com>
Subject HBase Client: How can I merge 2 results into 1?
Date Thu, 12 Dec 2013 18:27:27 GMT

I am using version 0.94.14 and I am trying to merge KeyValues of 2 results
into 1 result.

Basically somewhere in time I cache a keyvalue of a result:

### Putting in cache KeyValue with key:
tableName: STOCK, Family: 1, Qualifier: c, Value: ^@^@^@3

Later I get that KeyValue from my cache and add it to a list
(List<KeyValues> kvs). Then I add some more KeyValues from a Result
instance to that list:

            Collections.sort(kvs, KeyValue.COMPARATOR);

Finally, I build a new result with all those KeyValues ( new Result(kvs) ).

When I iterate through the map of that result I can read all values

            for (byte[] f : result.getMap().keySet()) {
                System.out.print("### Result2 Family: " +
                for (byte[] q : result.getFamilyMap(f).keySet()) {
                    System.out.print(" : Qualifier: " + Bytes.toString(q) +
" :: Value: "

But if I try to get values using result.getValue(...):

 for (byte[] f : result.getMap().keySet()) {
                System.out.print("### Result Family: " + Bytes.toString(f));
                for (byte[] q : result.getMap().get(f).keySet()) {
                    System.out.print(" : Qualifier: " + Bytes.toString(q) +
" :: Value: " + Bytes.toString(result.getValue(f, q)));

I only get the 2 first values, others are returned as null.

Here is the kvs list (where the first KeyValue was merged with the other 5

### KVS Key:
Family: 1, Qualifier: c, Value: ^@^@^@3
### KVS Key:
Family: 1, Qualifier: j, Value: niutpzbmnewnfsowrlauxeda
### KVS Key:
Family: 1, Qualifier: n, Value: ^@^@^@^@
### KVS Key:
Family: 1, Qualifier: o, Value: ^@^@^@^@
### KVS Key:
Family: 1, Qualifier: p, Value: ^@^@^@^@
### KVS Key:
Family: 1, Qualifier: q, Value:
kvs length: 6

I tried to look further inside the code of Result.getValue and I noticed
that this line:
int pos = Arrays.binarySearch(kvs, searchTerm, KeyValue.COMPARATOR);
is returning -2 to the last 4 KeyValues in the kvs list, and that's why I
was getting those values as null.

(If I do not merge the first KeyValue the pos is returned correctly)

Why does this happen? What am I doing wrong?


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message