scala操作Hbas -全表扫描

版权声明:test https://blog.csdn.net/weixin_37275456/article/details/85091125
package com.blm.util

import javax.ws.rs.core.Response.Status.Family
import org.apache.hadoop.hbase.{CellUtil, HBaseConfiguration, TableName}
import org.apache.hadoop.hbase.client._
import org.apache.hadoop.hbase.util.Bytes

class HbaseUtil {
    
    
    var conf = HBaseConfiguration.create()
    conf.set("hbase.zookeeper.quorum", "aiszk2.boloomo.com,aiszk1.boloomo.com,aiszk3.boloomo.com")
    var connection = ConnectionFactory.createConnection(conf)
    
    
    
    
    def getHbaseTable( tableName: String): Table = {
        val table = connection.getTable(TableName.valueOf(tableName))
        table
    }
    
    
    def getResultList(tableName:String,family: String,column:String): Unit =
    {
        
        val table = connection.getTable(TableName.valueOf(tableName))
        val scan = new Scan()
        scan.addFamily(family.getBytes())
        scan.addColumn(family.getBytes(),column.getBytes())
        
        
        val scanner = table.getScanner(scan).iterator()
        
        while (scanner.hasNext)
            {
                val result:Result = scanner.next()
                val row = result.rawCells()
                for(cell<-row)
                    {
                        val key = Bytes.toString(CellUtil.cloneRow(cell))
                        val fam = Bytes.toString(CellUtil.cloneFamily(cell))
                        val clumn = Bytes.toString(CellUtil.cloneQualifier(cell))
                        val value  = Bytes.toString(CellUtil.cloneValue(cell))
                        println(key+":"+fam+":"+clumn+":"+value)
                    }
            }     
    }  
}







猜你喜欢

转载自blog.csdn.net/weixin_37275456/article/details/85091125