tags:

views:

1378

answers:

1

I have a Thrift php client and I want to write in a HBase table and I'm doing 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 inserting in HBase the value, which is an array, gets converted to 'Array' instead of storing the elements of the array. How can I store the list as an array (or byte array)

+1  A: 

I must admit that I do not have a clue what you're trying to do (perhaps due to a lack of knowledge regarding Thrift and HBase), but if I understood your question correctly, you're trying to write some PHP data structure (array in this case) to a storage media. To achieve this you have to serialize your data somehow. That could be using a custom XML serialization, a custom binary serialization or, perhaps the most simple solution, the PHP internal serialization mechanism provided by serialize() and the corresponding unserialize().

If you strive for inter-language-interoperability you should use a custom serialization or you have to write a unserialization function that unserializes the PHP serialization format in your target language.

Just a quick example - I don't know where you'd have to put this code, as I don't know exactly what you're 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 seee

Stefan Gehrig
Thanks for the answer, I know the Php serialization mechanism but what I was wondering was if there is a way to write the PHP array as a byte array in a Hbase column. I have used the HBase.thrift file that comes to hbase to generate the php client, used the DemoClient.php file to do the testing, and HBAse thrift server to do the testing. I think, but not sure, that this relates to the way the structures are defined in HBase.thrift file