You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hbase.apache.org by Allan Spiegel <as...@adobe.com> on 2011/12/07 22:20:15 UTC

convert Hbase byte array to long in python?

I'm trying to write some Hbase test cases in python using the thrift client.  I'm having trouble figuring out how to convert the Hbase values (byte arrays) into their original form, a Long.

While we're at it, I'm sure I'll need to convert in the other direction at some point (long to byte array)

Thanks!

RE: convert Hbase byte array to long in python?

Posted by Allan Spiegel <as...@adobe.com>.
Thanks that works.

--Allan

-----Original Message-----
From: Todd Lipcon [mailto:todd@cloudera.com] 
Sent: Wednesday, December 07, 2011 4:28 PM
To: dev@hbase.apache.org
Subject: Re: convert Hbase byte array to long in python?

You probably want to use the "struct" module:

In [3]: struct.unpack(">q", "\x00\x00\x00\x00\x00\x00\x00\x05")
Out[3]: (5,)
In [4]: struct.pack(">q", 5)
Out[4]: '\x00\x00\x00\x00\x00\x00\x00\x05'

On Wed, Dec 7, 2011 at 1:20 PM, Allan Spiegel <as...@adobe.com> wrote:
>
> I'm trying to write some Hbase test cases in python using the thrift client.  I'm having trouble figuring out how to convert the Hbase values (byte arrays) into their original form, a Long.
>
> While we're at it, I'm sure I'll need to convert in the other direction at some point (long to byte array)
>
> Thanks!



-- 
Todd Lipcon
Software Engineer, Cloudera

Re: convert Hbase byte array to long in python?

Posted by Todd Lipcon <to...@cloudera.com>.
You probably want to use the "struct" module:

In [3]: struct.unpack(">q", "\x00\x00\x00\x00\x00\x00\x00\x05")
Out[3]: (5,)
In [4]: struct.pack(">q", 5)
Out[4]: '\x00\x00\x00\x00\x00\x00\x00\x05'

On Wed, Dec 7, 2011 at 1:20 PM, Allan Spiegel <as...@adobe.com> wrote:
>
> I'm trying to write some Hbase test cases in python using the thrift client.  I'm having trouble figuring out how to convert the Hbase values (byte arrays) into their original form, a Long.
>
> While we're at it, I'm sure I'll need to convert in the other direction at some point (long to byte array)
>
> Thanks!



-- 
Todd Lipcon
Software Engineer, Cloudera

Re: convert Hbase byte array to long in python?

Posted by Lars George <la...@gmail.com>.
Did you see Mozilla's HBase Thrift client?

http://code.google.com/p/socorro/source/browse/trunk/socorro/hbase/?r=1763

Lars

On Dec 7, 2011, at 22:20, Allan Spiegel <as...@adobe.com> wrote:

> 
> I'm trying to write some Hbase test cases in python using the thrift client.  I'm having trouble figuring out how to convert the Hbase values (byte arrays) into their original form, a Long.
> 
> While we're at it, I'm sure I'll need to convert in the other direction at some point (long to byte array)
> 
> Thanks!