2

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

我遇到了不同类型的问题,从 python 中执行 put。据我了解,最近的问题似乎与库兼容性问题有关。错误日志显示了迭代项的问题。happybase 手册引用了排序查询所需的其他 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'

现在蟒蛇:

>>> 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 Runtime Environment (build 1.8.0_31-b13) Java HotSpot(TM) 64-Bit Server VM (build 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'
4

2 回答 2

12

Happybase 作者在这里。

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

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

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

>>> table.put('2',{'f1': 'hey'})
于 2015-05-03T12:47:00.220 回答
1

尝试:

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

如果您有 f1 的子列,例如 col1、col2,您还可以指定特定的子列

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

欲了解更多信息,请关注:

https://happybase.readthedocs.io/en/happybase-0.4/tutorial.html

于 2017-04-26T09:16:29.787 回答