123456789101112131415161718192021222324252627282930313233 |
- package com.winhc.bigdata.flink.implicits
- import org.apache.hadoop.hbase.client.Result
- import org.apache.hadoop.hbase.util.Bytes
- import scala.collection.JavaConverters._
- import scala.collection.mutable.Map
- /**
- * @author: XuJiakai
- * @date: 2021/8/31 17:29
- */
- case class HbaseResultHelper(result: Result) {
- def toJsonString(): String = {
- if (result == null || result.isEmpty) {
- null
- } else {
- val map: Map[String, String] = Map()
- var rowkey: String = null
- for (cell <- result.listCells().asScala) {
- if (rowkey == null) {
- rowkey = Bytes.toString(cell.getRowArray, cell.getRowOffset, cell.getRowLength)
- }
- val key = Bytes.toString(cell.getQualifierArray, cell.getQualifierOffset, cell.getQualifierLength)
- val v = Bytes.toString(cell.getValueArray, cell.getValueOffset, cell.getValueLength)
- map += key-> v
- }
- map += "rowkey" -> rowkey
- map.toJson
- }
- }
- }
|