You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by ch huang <ju...@gmail.com> on 2013/07/15 10:08:58 UTC

can hbase used to store struct data?

i want to store json into hbase ,but i store as key-value ,the struct is
destory,any good idea?

Re: can hbase used to store struct data?

Posted by Flavio Pompermaier <po...@okkam.it>.
For me the same. I store the value as a string and the conversion is
carried out via Jackson 2.2.2 that does all the magic of
serialization/deserialization!
I store the json in a column named "value:json". For example this is my
map():

public void map(ImmutableBytesWritable row, Result columns, Context context)
throws IOException, InterruptedException {
for (KeyValue column : columns.list()) {
 final byte[] columnValue = column.getValue();
final byte[] columnFamily = column.getFamily();
final byte[] columnQualifier = column.getQualifier();
 final String family = Bytes.toString(columnFamily);
final String qual = Bytes.toString(columnQualifier);
 boolean isJsonColumn = "value".equals(family) && "json".equals(qual);
if (columnValue.length > 0 && isJsonColumn) {
                                String jsonString =
Bytes.toString(columnValue);
final ObjectMapper mapper = new ObjectMapper();
   MyObject myobj = mapper.readValue(jsonString, MyObject.class);
myobj.doSomething();
 }
}
}

Best,
Flavio

On Mon, Jul 15, 2013 at 2:52 PM, Ted Yu <yu...@gmail.com> wrote:

> What serialization / deserialization method did you use ?
>
> What HBase version are you using
>
> Thanks
>
> On Jul 15, 2013, at 1:08 AM, ch huang <ju...@gmail.com> wrote:
>
> > i want to store json into hbase ,but i store as key-value ,the struct is
> > destory,any good idea?
>

Re: can hbase used to store struct data?

Posted by Ted Yu <yu...@gmail.com>.
What serialization / deserialization method did you use ?

What HBase version are you using 

Thanks 

On Jul 15, 2013, at 1:08 AM, ch huang <ju...@gmail.com> wrote:

> i want to store json into hbase ,but i store as key-value ,the struct is
> destory,any good idea?

Re: can hbase used to store struct data?

Posted by Jean-Marc Spaggiari <je...@spaggiari.org>.
JSon is just a string at the end. And a string is just a bunch of bytes.
Just store it as your value. This is what I'm doing on my production
cluster ;)

JM

2013/7/15 ch huang <ju...@gmail.com>

> i want to store json into hbase ,but i store as key-value ,the struct is
> destory,any good idea?
>