hbase-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stack <st...@duboce.net>
Subject Re: Hbase incr function
Date Fri, 12 Mar 2010 15:42:38 GMT
Everything in hbase is a byte array.  Counters are converted from
numbers to bytes when stored to hbase.

Neither does hbase store column type information so whether the column
value is a number or string is an application concern and opaque to
hbase.

What you are seeing below is the shell outputting the raw counter
bytes.  As written it doesn't know any better regards the cell
content.  What we should do is add to the shell a get_counter or some
such method that will take the bytes from the specified cell value and
emit them as a number (I made an issue to do this, HBASE-2314).  You
the user know the cell contains a counter and would use the
get_counter to fetch the current contents.

Meantime, a bit of shell hackery should do the job for you.  Something
like the following pseudo-code:

hbase> t = HTable.new(@configuration, "TABLE_NAME")
hbase> g = Get.new(Bytes.toBytes("ROW_STR")
hbase> f = Bytes.toBytes("FAMILY")
hbase> q = Bytes.toBytes("QUALFIER")
hbase> g.addColumn(f, q)
hbase> result = t.get(g)
hbase> puts Bytes.toInteger(result.get(g, q))

Make above into a method... etc.

Good luck,
St.Ack

On Fri, Mar 12, 2010 at 7:11 AM, Ray Duong <ray.duong@gmail.com> wrote:
> Hi Hbase,
>
> I'm a little confuse on how the auto increment works in Hbase.  Shouldn't
> the value be a number instead of a bytearray?  Is there a way to convert the
> value into a string?
>
>
> hbase(main):013:0> create 'testcounter', 'cf'
> 0 row(s) in 2.0950 seconds
> 3854.986: [GC 3854.987: [ParNew: 19136K->1671K(19136K), 0.0175270 secs]
> 27147K->11204K(83008K) icms_dc=7 , 0.0177320 secs] [Times: user=0.02
> sys=0.03, real=0.01 secs]
> hbase(main):014:0> scan 'testcounter'
> ROW
> COLUMN+CELL
>
> 0 row(s) in 0.0080 seconds
> hbase(main):015:0> incr 'testcounter', 'r1', 'cf:counter', 1
> 0 row(s) in 0.0040 seconds
> hbase(main):016:0> scan 'testcounter'
> ROW
> COLUMN+CELL
>
>  r1                          column=cf:counter, timestamp=1268406376222,
> value=\x00\x00\x00\x00\x00\x00\x00\x0
>
> 1
>
> 1 row(s) in 0.0110 seconds
> hbase(main):017:0> incr 'testcounter', 'r1', 'cf:counter', 1
> 0 row(s) in 0.0030 seconds
> hbase(main):018:0> scan 'testcounter'
> ROW
> COLUMN+CELL
>
>  r1                          column=cf:counter, timestamp=1268406376222,
> value=\x00\x00\x00\x00\x00\x00\x00\x0
>
> 2
>
> 1 row(s) in 0.0090 seconds
> hbase(main):019:0> incr 'testcounter', 'r1', 'cf:counter', 1
> 0 row(s) in 0.0040 seconds
> hbase(main):020:0> scan 'testcounter'
> ROW
> COLUMN+CELL
>
>  r1                          column=cf:counter, timestamp=1268406376222,
> value=\x00\x00\x00\x00\x00\x00\x00\x0
>
> 3
>
> 1 row(s) in 0.0080 seconds
> hbase(main):021:0> incr 'testcounter', 'r1', 'cf:counter', 10
> 0 row(s) in 0.0040 seconds
> hbase(main):022:0> scan 'testcounter'
> ROW
> COLUMN+CELL
>
>  r1                          column=cf:counter, timestamp=1268406376222,
> value=\x00\x00\x00\x00\x00\x00\x00\x0
>
> D
>
> 1 row(s) in 0.0090 seconds
> hbase(main):023:0> incr 'testcounter', 'r1', 'cf:counter', 100
> 0 row(s) in 0.0030 seconds
> hbase(main):024:0> scan 'testcounter'
> ROW
> COLUMN+CELL
>
>  r1                          column=cf:counter, timestamp=1268406376222,
> value=\x00\x00\x00\x00\x00\x00\x00q
> 1 row(s) in 0.0230 seconds
>
> Thanks,
> -ray
>

Mime
View raw message