python - 从 python (happybase) 写入 hbase 表

标签 python hadoop hbase thrift happybase

我正在运行一个 map-reduce 作业,现在我想将值输入到 hbase 中。我通过 stdin 从 map-reduce 作业流式传输值,并有一个 python 脚本在 happybase 上插入(放置)行.

我遇到了不同类型的问题,从 python 执行 put。据我了解,最近的问题似乎与库兼容性问题有关。错误日志显示 iteritems 的问题。 happybase manual指的是排序查询所需的额外 python 库,从 python 版本 2.7 开始不需要这些库(我运行的是 2.7.6)。

有没有人遇到过类似的问题?它们可以很容易地修复吗,或者您会推荐使用不同的界面吗?

更多详情

我安装了 hadoop (2.6.0) 和 hbase (0.98.10 - 2/5/2015) 并以独立配置运行。他们启动了。我可以通过 shell 与 hbase 交互、创建表、输入值并扫描它们。

我可以通过 happybase 从 python 扫描和打印表格,这至少表明连接有效。但是 put 总是失败。这个简短的例子说明了问题:

为了这个例子,我的表被称为 test(在 hbase shell 中创建)。它只有一列f1

hbase(main)> create 't1','f1'
hbase(main)> put 't1','1','f1','hello'

现在 python :

>>> import happybase
>>> connection = happybase.Connection('localhost')
>>> table = connection.table('t1')
>>> print(table.row('1')) # {'f1:': 'hello'}
>>> table.put('2',{'f1','hey'}) # fails, see log

更多细节:

节俭正在运行。

# hbase thrift start -threadpool


hduser@box> hbase -version

Java 版本“1.8.0_31” Java(TM) SE 运行时环境(build 1.8.0_31-b13) Java HotSpot(TM) 64 位服务器 VM(构建 25.31-b07,混合模式)

错误日志:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-15-56dab4cd31ef> in <module>()
----> 1 table.put('2',{'f1','hey'})

/usr/local/lib/python2.7/dist-packages/happybase/table.pyc in put(self, row, data, timestamp, wal)
    437         """
    438         with self.batch(timestamp=timestamp, wal=wal) as batch:
--> 439             batch.put(row, data)
    440 
    441     def delete(self, row, columns=None, timestamp=None, wal=True):

/usr/local/lib/python2.7/dist-packages/happybase/batch.pyc in put(self, row, data, wal)
     81                 value=value,
     82                 writeToWAL=wal)
---> 83             for column, value in data.iteritems())
     84 
     85         self._mutation_count += len(data)

AttributeError: 'set' object has no attribute 'iteritems'

最佳答案

这里是 Happybase 作者。

您代码中的这一行包含错误:

>>> table.put('2',{'f1','hey'}) # fails, see log

{'f1', 'hey'} 是一个集合文字,而您应该传递一个字典。我猜你是这个意思吧?

>>> table.put('2',{'f1': 'hey'})

关于python - 从 python (happybase) 写入 hbase 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28456422/

相关文章:

hadoop - Mahout 0.8和hadoop 0.21

installation - HBase/Zookeeper 安装问题

hbase - 在 HBase 中存储 JSON 并按 Id 查询

hadoop - 通过 Hive 外部表将 Hbase 数据索引到 solr

javascript - 使用 Babel CLI 提取器提取 Javascript gettext 消息

javascript - 相当于 Python str() 方法的 JS

hadoop - Hortonworks 数据平台 2.4(沙盒): Directory structure

python - 如何在 <img src> 中添加 django 模板变量?

python - 添加更多 Python 库

java - TProtocolException : Missing version in readMessageBegin, 旧客户端