Hbase的工具类
程序员文章站
2022-04-08 22:45:35
以下为hbase在java客户端中会用到的工具类:package com.doit.oneMore.tools;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.hbase.Cell;import org.apache.hadoop.hbase.CellUtil;import org.apache.hadoop.hbase.HBaseConfiguration;import org.apache.had...
以下为hbase在java客户端中会用到的工具类:
package com.doit.oneMore.tools;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import java.io.IOException;
/**
* Author: reddy
* Date: 2020/7/17
* Description:1获取连接
*/
public class HbaseTools {
/*
获取hbase连接对象
*/
public static Connection getHbaseConnection() throws Exception {
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum","linux01:2181,linux02:2181,linux03:2181");
return ConnectionFactory.createConnection(conf);
}
/*
获取Hbase的管理对象
*/
public static Admin getHbaseAdmin() throws Exception {
return getHbaseConnection().getAdmin();
}
/*
获取表对象
*/
public static Table getTable(String tbName) throws Exception {
return getHbaseConnection().getTable(TableName.valueOf(tbName));
}
/*
展示数据
*/
public static void showData(Result res){
if(res!=null){
while(res.advance()){
Cell cell = res.current();
byte[] row = CellUtil.cloneRow(cell);
byte[] family = CellUtil.cloneFamily(cell);
byte[] qualifier = CellUtil.cloneQualifier(cell);
byte[] value = CellUtil.cloneValue(cell);
System.out.println("行键"+row+"=="+"列族"+family+"=="+"属性"+qualifier+"=="+"值"+value);
}
}
}
}
本文地址:https://blog.csdn.net/reddy_Hu/article/details/107417484
上一篇: ospf基本架构
下一篇: modem 高通log