Spark doBulkLoad数据入hbase 踩坑

网上有很多spark生成HFIle文件导入到HBase的例子,但是参考网上例子再结合自己的程序依然有很多bug,之前采用如下这种方式:

val tableName= PRE_WTB + dataDate //表名
createTable(conf, wzktb, Array(CF), 2)  //创建hbase表
conf.set(TableOutputFormat.OUTPUT_TABLE, tableName)
val wzktbRDD = rdd
      .flatMap(s => {
        val cl = s.split("\t",-1)
        val hm = “”
        val kh = “”
        val rowKey = timeSection 

        val put: Put = new Put(Bytes.toBytes(rowKey))
        val famliy = Bytes.toBytes("cf")  // HBase 列族是固定的
        if(hm != "" && kh != ""){
          put.addColumn(famliy, Bytes.toBytes("1_" + hm), Bytes.toBytes(""))
          put.addColumn(famliy, Bytes.toBytes("2_" + kh), Bytes.toBytes(""))
        }else if(hm == ""){
          put.addColumn(famliy, Bytes.toBytes("2_" + kh), Bytes.toBytes(""))
        }else {
          put.addColumn(famliy, Bytes.toBytes("1_" + hm), Bytes.toBytes(""))
        }
        Array(Tuple2(String.valueOf(System.currentTimeMillis()), put))
      })
    wzktbRDD.saveAsNewAPIHadoopFile(wzktb, classOf[String], classOf[Put], classOf[TableOutputFormat[String]], conf)

在数据量不大的情况下这种入库方式完全可以满足业务需求,但当数据量达到几亿十几亿数量级别后入库时间就到了小时级别,严重影响性能。

在网上参考其大神的博客尝试采用doBulkLoad方式,参考网上的例子写了如下代码:

val conf = HBaseConfiguration.create()
val conn = ConnectionFactory.createConnection(conf)
val tableName= PRE_WTB + dataDate;//表名
val table = conn.getTable(TableName.valueOf(tableName))
val regionLocator = conn.getRegionLocator(TableName.

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值