下面说说java api 提供的这些类的功能和他们之间有什么样的联系。
1.hbaseconfiguration
关系:org.apache.hadoop.hbase.hbaseconfiguration
作用:通过此类可以对hbase进行配置
用法实例: configuration config = hbaseconfiguration.create();
说明: hbaseconfiguration.create() 默认会从classpath 中查找 hbase-site.xml 中的配置信息,初始化 configuration。
2.hbaseadmin 类
关系:org.apache.hadoop.hbase.client.hbaseadmin
作用:提供接口关系hbase 数据库中的表信息
用法:hbaseadmin admin = new hbaseadmin(config);
3.descriptor类
关系:org.apache.hadoop.hbase.htabledescriptor
作用:htabledescriptor 类包含了表的名字以及表的列族信息
用法:htabledescriptor htd =new htabledescriptor(tablename);
构造一个表描述符指定tablename对象。
htd.addfamily(new hcolumndescriptor(“myfamily”));
将列家族给定的描述符
4.htable
关系:org.apache.hadoop.hbase.client.htable
作用:htable 和 hbase 的表通信
用法:htable tab = new htable(config,bytes.tobytes(tablename));
resultscanner sc = tab.getscanner(bytes.tobytes(“familyname”));
说明:获取表内列族 familynme 的所有数据。
5.put
关系:org.apache.hadoop.hbase.client.put
作用:获取单个行的数据
用法:htable table = new htable(config,bytes.tobytes(tablename));
put put = new put(row);
p.add(family,qualifier,value);
说明:向表 tablename 添加 “family,qualifier,value”指定的值。
6.get
关系:org.apache.hadoop.hbase.client.get
get get = new get(bytes.tobytes(row));
result result = table.get(get);
说明:获取 tablename 表中 row 行的对应数据
7.resultscanner
关系:interface
作用:获取值的接口
用法:resultscanner scanner = table.getscanner(bytes.tobytes(family));
for(result rowresult : scanner){
bytes[] str = rowresult.getvalue(family,column);
}
说明:循环获取行中列值。
例1 hbase之读取hdfs数据写入hbase
例2 hbase之读取hbase数据写入hdfs
程序中用到hadoop的相关jar包(如下图)及hbase所有jar包
如果上面的api还不能满足你的要求,可以到下面这个网站里面hbase全部api介绍
<a href="http://www.yiibai.com/hbase/" target="_blank">http://www.yiibai.com/hbase/</a>