2017-08-20 166 views
0

我在通过流式jar包运行的python中编写了MR作业。我想知道如何使用批量加载将数据放入HBase。如何将数据批量加载到python中的hbase

我知道有2种方式通过批量加载将数据导入hbase。

  1. 在MR作业中生成HFile,并使用CompleteBulkLoad将数据加载到hbase中。
  2. 使用ImportTsv选项,然后使用CompleteBulkLoad加载数据。

我不知道如何使用python生成HFile来适应Hbase。然后我尝试使用ImportTsv实用程序。但失败了。我跟着这个[示例](http://hbase.apache.org/book.html#importtsv)的说明。但我得到异常:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/filter/Filter...

现在我要问3个问题:

  1. 无论是Python的可用于通过流罐子产生HFILE或不。
  2. 如何使用importtsv。
  3. 可以使用bulkload来更新Hbase中的表。我每天收到一个大于10GB的大文件。可以使用bulkload将文件推送到Hbase。

Hadoop的版本是:Hadoop的2.8.0

HBase的版本是:HBase的1.2.6

在独立模式下运行的两种。

感谢您的任何答案。

--- 更新 ---

ImportTsv正常工作。

但我仍然想知道如何通过在Python语言中流式传输jar来在MR作业中生成HFile。

回答

0

你可以试试happyBase

table = connection.table("mytable") 
with table.batch(batch_size=1000) as b: 
    for i in range(1200): 

     b.put(b'row-%04d'.format(i), { 
      b'cf1:col1': b'v1', 
      b'cf1:col2': b'v2', 
     }) 

As you may have imagined already, a Batch keeps all mutations in memory until the batch is sent, either by calling Batch.send() explicitly, or when the with block ends. This doesn’t work for applications that need to store huge amounts of data, since it may result in batches that are too big to send in one round-trip, or in batches that use too much memory. For these cases, the batch_size argument can be specified. The batch_size acts as a threshold: a Batch instance automatically sends all pending mutations when there are more than batch_size pending operations.

这需要HBase的前一个节俭服务器立场。只是一个建议。

+0

感谢您的回答。但幸福感似乎不适合我的问题。大文件的速度有点慢。 – litao3rd

相关问题