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

Switch to Plain View
HBase, mail # user - KeyValue.getLength() question


+
Kim Chew 2013-09-25, 07:06
+
Robert Dyer 2013-09-25, 07:13
+
Kim Chew 2013-09-25, 17:12
Copy link to this message
-
Re: KeyValue.getLength() question
lars hofhansl 2013-09-26, 04:23
That is correct.
If you do this on the client (for example with a KeyValue you got from a Result object) it might work, but generally you cannot do this.

This, however will always work:

KeyValue kv = ...;

KeyValue myKv = new KeyValue(kv.getBuffer(), kv.getOffset());
byte[] myRowKey = myKv.getRow();
Think of a KeyValue object as a "pointer" into a larger byte[]. Java (unfortunately!) does not have pointers, so we have to pass the array and an offset around.

-- Lars
----- Original Message -----
From: Kim Chew <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Cc:
Sent: Wednesday, September 25, 2013 10:12 AM
Subject: Re: KeyValue.getLength() question

hmm, does it mean if I do something like this, I won't get the correct
KeyValue object back?

byte[] rowKey = kv.getRow();
byte[] buf = kv.getBuffer();
KeyValue myKv = new KeyValue(buf);
byte[] myRowKey = myKv.getRow();

rowKey will not be equal to myRowKey.

Kim
On Wed, Sep 25, 2013 at 12:13 AM, Robert Dyer <[EMAIL PROTECTED]> wrote:

> Note that the buffer may be larger than the actually used portion.
>
> myKV.getBuffer().length gives you the length of the buffer (allocated
> array)
> myKV.getLength() gives you the length of the USED buffer (less than or
> equal to the previous)
>
>
> On Wed, Sep 25, 2013 at 2:06 AM, Kim Chew <[EMAIL PROTECTED]> wrote:
>
> > Hello,
> >
> > I have a "strange" situation that I can't wrap my head around it. Say,
> for
> > example, I have an KeyValue instance, shouldn't
> >
> >     myKV.getLength() == myKV.getBuffer().length ?
> >
> > Given that, "getLength()" returns "Length of bytes this KeyValue occupies
> > in getBuffer()<
> >
> http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/KeyValue.html#getBuffer%28%29
> > >
> > ."
> >
> >
> > In my case the value returned by "myKV.getBuffer().length" is greater
> than
> > "myKV.getLength()". What possibly went wrong?
> >
> > TIA
> >
> > Kim.
> >
>
>
>
> --
>
> Robert Dyer
> [EMAIL PROTECTED]
>
+
lars hofhansl 2013-09-25, 14:52
+
Kim Chew 2013-09-26, 00:40
+
lars hofhansl 2013-09-26, 04:30
+
Kim Chew 2013-09-28, 00:20