HBase基础知识点,HBase基础知识
HBase 基本概念
HBase 的基本特点
常见的大数据库产品
Google的BigTable
Apache的Cassandra、HBase
HBase相关
zookeeper file中记录了-ROOT-表的Location
-ROOT-
记录了.META表的Region信息
-ROOT- 只有一个Region
将.META中的Region映射到Region Server上
该表主要存储了.META服务器位置以及映射了那些META Region
.META
记录了用户表的Region信息
.META可以有多个Region
包括Region中数据起止行信息,Region“在线”状态等
保存Region Server的地址
SingleColumnFilter:列值过滤器(专用过滤器)
用一列的值决定是否一行数据被过滤
FilterList:过滤器列表
FilterList.Operator 可选枚举项:
MUST_PASS_ALL 所有过滤器都允许包含这个值
MUST_PASS_ONE 只有一个过滤器允许包括这个值
比较过滤器:
基于列限定符的过滤器:QualifierFilter
列前缀过滤器:ColumnPrefixFilter
比较器:
完全匹配:BinaryComparator
从左端开始前缀匹配:BinaryPrefixComparator
HBase 常用命令
create 'scores','grade'
向"scores"表加入一行数据,rowkey为"zkb",列族为"grade",列限定符为"class",值为"5" put 'scores','zkb','grade:class','5'
查询整行数据 get'scores','zkb'
查询列族grade的数据 get'scores','zkb’,'grade'
查询列族grade中列class的数据 get'scores','zkb’,'grade:class'
全表查询 scan 'scores'
按rowkey的范围查询
scan 'scores',{STARTROW=>'001',STOPROW=>'005'}
删除记录 delete 'scores','001','grade:class'
删除表,在删除表之前要disable,防止删除过程中访问该表 disable 'scores' drop 'scores'
Java API
public void scan(String tablename) throws Exception{
HTable table = new HTable(conf,tablename);
Scan s = new Scan();
ResultScanner rs = table.getScanner(s);
for(Result r : rs){
byte[] row = r.getRow();
byte[] value = r.getValue(Bytes.toBytes("grade"),Bytes.toBytes("class"));
System.out.println("Scan:" + Bytes.toString(row) + " is in class " + Bytes.toString(value));
}
rs.close();
table.close();
}
public void get(String tablename,String row) throws Exception{
HTable table = new HTable(conf,tablename);
Get g = new Get(Bytes.toBytes(row));
Result result = table.get(g);
byte[] value = result.getValue(Bytes.toBytes("grade"), Bytes.toBytes("class"));
System.out.println("Get:" + row + "=> class is " + Bytes.toString(value));
table.close();
}
public void put(String tablename,String row,String columnFamily,String column,String data) throws Exception{
HTable table = new HTable(conf,tablename);
Put p1 = new Put(Bytes.toBytes(row));
p1.add(Bytes.toBytes(columnFamily),Bytes.toBytes(column),
Bytes.toBytes(data));
table.put(p1);
System.out.println(row +" putted");
table.close();
}
public void createTable(String strTab, String[] arrCF) throws Exception{
HBaseAdmin admin = null;
admin = new HBaseAdmin(conf);
if(admin.tableExists(strTab)){
System.out.println(strTab + "already exists");
}else{
HTableDescriptor ts = new HTableDescriptor(strTab);
for (int i = 0 ; i< arrCF.length; i++){
ts.addFamily(new HColumnDescriptor(arrCF[i]));
}
admin.createTable(ts);
System.out.println(strTab + " is created");
}
dmin.close();
}
public void deleteTable(String strTab) throws Exception{
HBaseAdmin admin = null;
admin = new HBaseAdmin(conf);
if(!admin.tableExists(strTab)){
System.out.println(strTab + " is not exists");
}else{
admin.disableTable(strTab);
admin.deleteTable(strTab);
System.out.println(strTab + " is deleted");
}
admin.close();
}
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。