使用thrift在HBase中写入php数组
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HBase 突变对象需要三个带有布尔/文本值的字段,而不是数组。 因此,您需要将任何结构化值转换为字符串,例如。
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.
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.
我必须承认,我不知道你想要做什么(可能是由于缺乏有关 Thrift 和 HBase 的知识),但如果我正确理解你的问题,你正在尝试编写一些 PHP 数据结构(在本例中为数组)到存储介质。 为了实现这一点,您必须以某种方式序列化您的数据。 这可以使用自定义 XML 序列化、自定义二进制序列化,或者可能是最简单的解决方案,即
serialize()
提供的 PHP 内部序列化机制以及相应的unserialize()
。如果您努力实现语言间互操作性,则应该使用自定义序列化,或者必须编写一个反序列化函数,以目标语言反序列化 PHP 序列化格式。
只是一个简单的例子 - 我不知道你必须把这段代码放在哪里,因为我不知道你到底在做什么:
请参阅
serialize()
unserialize()
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 correspondingunserialize()
.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:
Please seee
serialize()
unserialize()