Is this method correct for storing HBase data?

Here I want me to want to store and retrieve serialized data in an HBase table, and later I want to get it as it is. I thought to follow the method. Please tell me if I am wrong.

put.add(streamColumnFamily,streamColumnName,serializedData);

Here, the serializedData attribute will be handled by the HBaseSerialization class . what he wants is the right method. I can get the saved data as is. (int as int, float as float, String as String, etc.)

0
source share
1 answer

Yes, the method is correct. HBase stores everything in bytes. You basically do something like

byte[] key = createSomeKey();

Put put = new Put(key);
put.add(streamColumnFamily,streamColumnName,serializedData); 

HTable h = .... // create HTable from HAdmin 

h.put(put);

java :

   public byte[] serialize(Serializable object) throws IOException {


      ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

      ObjectOutput stream = new ObjectOutputStream(byteArrayOutputStream);

      stream.writeObject(object);

      stream.flush();

      return byteArrayOutputStream.toByteArray()
    }


public Object deserialize(byte[] bytes){

     ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);

     ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);

     objectInputStream.readObject(); 
   }

, , Integer, Long, String..., Bytes org.apache.hadoop.hbase.util

+2

Source: https://habr.com/ru/post/1772836/


All Articles