Write a php array in HBase using economy

I have a Thrift php client, and I want to write in an HBase table, and I do the following:

$mutations = array( new Mutation( array( 'column' => 'entry:num', 'value' => array('a','b','c') ) ), ); $client->mutateRow( $t, $row, $mutations ); 

The problem is that when pasted into HBase, the value, which is an array, is converted to an "Array" instead of storing the elements of the array. How to save a list as an array (or an array of bytes)

+4
source share
2 answers

An HBase mutation object requires three fields with Boolean / text values, not arrays. So you need to turn any structured value into a string, something like.

  $mutations = array( new Mutation( array( 'isDelete' => FALSE, 'column' => 'entry:num', 'value' => serialize(array('a','b','c')) ) ), ); $client->mutateRow( $t, $row, $mutations ); 

The definition of the HBase Thrift API is here; http://svn.apache.org/viewvc/hbase/trunk/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift?view=markup

I have not tested this.

+3
source

I have to admit that I donโ€™t know what you are trying to do (possibly due to a lack of knowledge about Thrift and HBase), but if I understand your question correctly, you are trying to write some kind of PHP data structure (array in this case) to the storage medium. To do this, you need to somehow serialize your data. This could be using custom XML serialization, custom binary serialization, or perhaps the simplest solution, the PHP internal serialization mechanism provided by serialize() and the corresponding unserialize() .

If you want cross-language compatibility, you must use custom serialization or you need to write a non-serialization function that does not initialize the PHP serialization format in your target language.

Just a quick example - I donโ€™t know where you would have to put this code, since I donโ€™t know exactly what you are doing:

 $mutations = array( new Mutation(array( 'column' => 'entry:num', 'value' => array('a','b','c') )), ); $data = serialize($mutations); // $data now is a string // write $data to storage // read $readData from storage $readMutations = unserialize($readData); // $readMutations == $mutations // (but the Mutation instances are not the same instances any more) 

Please look

+2
source

All Articles