使用thrift在HBase中写入php数组

发布于 2024-07-19 19:48:35 字数 338 浏览 3 评论 0原文

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

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

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

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云柯 2024-07-26 19:48:35

HBase 突变对象需要三个带有布尔/文本值的字段,而不是数组。 因此,您需要将任何结构化值转换为字符串,例如。

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

HBase Thrift API 的定义在这里;
http://svn.apache.org/viewvc/hbase/trunk/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift?view=markup

我还没有测试过这个。

A HBase mutation object has required 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 haven't tested this.

薄荷→糖丶微凉 2024-07-26 19:48:35

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

请参阅

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文