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
Hi,

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:
\x00\x09\x00\x00\x00\x04\x00\x00\x00\x00\x07\x011c\x00\x00\x01B\xE2\xE0\x0C\xEF\x04,
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:

            kvs.addAll(partialResult.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
correctly:

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

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
KeyValues):

### KVS Key:
\x00\x09\x00\x00\x00\x04\x00\x00\x00\x00\x07\x011c\x00\x00\x01B\xE2\xE0\x0C\xEF\x04,
Family: 1, Qualifier: c, Value: ^@^@^@3
### KVS Key:
\x00\x09\x00\x00\x00\x04\x00\x00\x01a\x97\x011j\x00\x00\x01B\xE2\xE0\xF0\x9D\x04,
Family: 1, Qualifier: j, Value: niutpzbmnewnfsowrlauxeda
### KVS Key:
\x00\x09\x00\x00\x00\x04\x00\x00\x01a\x97\x011n\x00\x00\x01B\xE2\xE0\xF0\x9D\x04,
Family: 1, Qualifier: n, Value: ^@^@^@^@
### KVS Key:
\x00\x09\x00\x00\x00\x04\x00\x00\x01a\x97\x011o\x00\x00\x01B\xE2\xE0\xF0\x9D\x04,
Family: 1, Qualifier: o, Value: ^@^@^@^@
### KVS Key:
\x00\x09\x00\x00\x00\x04\x00\x00\x01a\x97\x011p\x00\x00\x01B\xE2\xE0\xF0\x9D\x04,
Family: 1, Qualifier: p, Value: ^@^@^@^@
### KVS Key:
\x00\x09\x00\x00\x00\x04\x00\x00\x01a\x97\x011q\x00\x00\x01B\xE2\xE0\xF0\x9D\x04,
Family: 1, Qualifier: q, Value:
nbdpcwgwriaysaiqgkfozcacvalqymmuybsaoodidnbbltioqh
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?

Thanks.

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