繁体   English   中英

从python(happybase)写入hbase表

[英]Writing to hbase table from python (happybase)

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

我遇到了各种各样的问题,从python执行put。 根据我的理解,最近的问题似乎与库兼容性问题有关。 错误日志显示iteritems的问题。 happybase手册指的是排序查询所需的其他python库,从python版本2.7开始不需要(我运行的是2.7.6)。

有没有人遇到类似的问题? 它们可以轻松修复,还是建议使用不同的界面?

更多细节

我在独立配置中安装并运行了hadoop(2.6.0)和hbase(0.98.10 - 2/5/2015)。 他们开始了。 我可以通过shell与hbase接口,创建表,输入值并扫描它们。

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

为了这个例子,我的表叫做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运行时环境(版本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'})

尝试:

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

如果你有f1的子列,如col1,col2,你也可以指定特定的子列

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

欲了解更多信息,请访

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM