How to store complex objects into hadoop Hbase?

十年热恋 提交于 2019-12-23 18:14:53

问题


I have complex objects with collection fields which needed to be stored to Hadoop. I don't want to go through whole object tree and explicitly store each field. So I just think about serialization of complex fields and store it as one big piece. And than desirialize it when reading object. So what is the best way to do it? I though about using some kind serilization for that but I hope that Hadoop has means to handle this situation.

Sample object's class to store:

class ComplexClass {

<simple fields>

List<AnotherComplexClassWithCollectionFields> collection;


}

回答1:


HBase only deals with byte arrays, so you can serialize your object in any way you see fit.

The standard Hadoop way of serializing objects is to implement the org.apache.hadoop.io.Writable interface. Then you can serialize your object into a byte array using org.apache.hadoop.io.WritableUtils.toByteArray(Writable ... writable).

Also, there are other serialization frameworks that people in the Hadoop community use, like Avro, Protocol Buffers, and Thrift. All have their specific use cases, so do your research. If you're doing something simple, implementing Hadoop's Writable should be good enough.



来源:https://stackoverflow.com/questions/4086684/how-to-store-complex-objects-into-hadoop-hbase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!