Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
HBase, mail # user - HBase Client: How can I merge 2 results into 1?


Copy link to this message
-
Re: HBase Client: How can I merge 2 results into 1?
lars hofhansl 2013-12-12, 21:21
Hi Saiph,

no need to apologize.
Please keep asking questions as you encounter issues. :)

-- Lars

________________________________
 From: Saiph Kappa <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Sent: Thursday, December 12, 2013 12:59 PM
Subject: Re: HBase Client: How can I merge 2 results into 1?
 

I apologize, but I did a mistake. I was merging keyvalues from different
rows (there was a problem in the way I was comparing and decoding the
byte[] of rows) into a single result, which is not possible naturally.

Therefore, I ask you to delete this thread.

Thanks and sorry for any inconvenience.

On Thu, Dec 12, 2013 at 6:27 PM, Saiph Kappa <[EMAIL PROTECTED]> wrote:

> 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.
>