使用 thrift 在 HBase 中编写 php 数组

5 php hbase thrift

我有一个 Thrift php 客户端,我想写入一个 HBase 表,我正在执行以下操作:

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

问题是在 HBase 中插入值时,该值是一个数组,被转换为 'Array' 而不是存储数组的元素。如何将列表存储为数组(或字节数组)

Ste*_*rig 2

我必须承认,我不知道你想要做什么(可能是由于缺乏有关 Thrift 和 HBase 的知识),但如果我正确理解你的问题,你正在尝试编写一些 PHP 数据结构(在本例中为数组)到存储介质。为了实现这一点,你必须以某种方式序列化你的数据。这可以使用自定义 XML 序列化、自定义二进制序列化,或者可能是最简单的解决方案,即由serialize()和相应的unserialize().

如果您努力实现语言间互操作性,则应该使用自定义序列化,或者必须编写一个反序列化函数,以目标语言反序列化 PHP 序列化格式。

只是一个简单的例子 - 我不知道你必须把这段代码放在哪里,因为我不知道你到底在做什么:

$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)
Run Code Online (Sandbox Code Playgroud)

请看