hbase获取/扫描烫伤作业

wvt8vs2t  于 2021-06-09  发布在  Hbase
关注(0)|答案(1)|浏览(390)

我在用spyglass烫伤来读写hbase。
我正在做一个表1和表2的左外连接,在转换一列之后写回表1。表1和表2都声明为spyglass HBasource。
这个很好用。但是,我需要使用rowkey访问表1中的另一行来计算转换后的值。
我为hbase get尝试了以下操作: val hTable = new HTable(conf, TABLE_NAME) val result = hTable.get(new Get(rowKey.getBytes())) 我正在访问烫伤作业中的配置,如此链接中所述:
https://github.com/twitter/scalding/wiki/frequently-asked-questions#how-do-i-access-the-jobconf访问
当我在本地运行烫伤作业时,这种方法有效。但是,当我在集群中运行它时,当这个代码在reducer中执行时,conf是空的。
对于这样的情况,有没有更好的方法来执行hbase get/scan中的烫伤/级联工作?

3hvapo4f

3hvapo4f1#

如何做到这一点。。。
1) 您可以使用托管资源

class SomeJob(args: Args) extends Job(args) {      
  val someConfig = HBaseConfiguration.create().addResource(new Path(pathtoyourxmlfile))
  lazy val hPool = new HTablePool(someConfig, 3)

  def getConf = {
    implicitly[Mode] match {
      case Hdfs(_, conf) => conf
      case _ => whateveryou are doing for a local conf...
    }
  }
  ... somePipe.someOperation.... {
        val gets = key.map { key => new Get(key) }
        managed(hPool.getTable("myTableName")) acquireAndGet { table => 
          val results = table.get(gets)
          ...do something with these results
        }
     }    
}

2) 您可以使用一些更具体的级联代码,在其中编写自定义方案,并在其中重写源方法,还可以根据需要重写其他一些方法。在这里,您可以访问jobconf,如下所示:

class MyScheme extends Scheme[JobConf, SomeRecordReader, SomeOutputCollector, ..] {

  @transient var jobConf: Configuration = super.jobConfiguration

  override def source(flowProcess: FlowProcess[JobConf], ...): Boolean = {
   jobConf = flowProcess match {
     case h: HadoopFlowProcess => h.getJobConf
     case _ => jconf
   }

   ... dosomething with the jobConf here

 }   

}

相关问题