hbase建表:
create 'test:medication', {NAME=>'p'}
其中test是表空间,hbase表名是medication,列族是p
添加数据:
put 'test:medication','2','p:ICD_CODE','B23'
向hbase中添加数据,rowkey是2
按照rowkey进行模糊查询:
scan ‘ihr:HealthExam_Reg’,{FILTER=>org.apache.hadoop.hbase.filter.PrefixFilter.new(org.apache.hadoop.hbase.util.Bytes.toBytes(‘pk_350203198909142016’))}
查询前几条数据:
scan 'test:medication',{LIMIT=>5}
hbase 删除表数据 :
truncate "test:medication"
查询条数:
count "ihr:sehr_xman_event"
count表时,默认是1000条可以通过修改INTERVAL更改查询条数:
count 'test:ming', INTERVAL => 100000
hbase大表数据通过MapReduce快速count计数:
$HBASE_HOME/bin/hbase org.apache.hadoop.hbase.mapreduce.RowCounter 'tablename'
删除表
分两步:首先disable,然后drop
删除表test:medication
disable 'test:medication'
drop 'test:medication'
hbase查看表大小:
hadoop fs -du -s -h /apps/hbase/data/data/你的表空间/你的表名
hbase更改表名
因为hbase中没有rename命令,所以在更改的时候比较复杂。hbase表重命名主要是通过hbase的快照功能实现的。
1.停止表继续插入 hbase shell>disable 'tableName'
2.制作快照 hbase shell>snapshot 'tableName','tableSnapshot'
3.克隆快照为新的名字 hbase shell> clone_snapshot 'tableSnapshot', 'newTableName'
4.删除快照 hbase shell> delete_snapshot 'tableSnapshot'
5.删除原来表 hbase shell> drop 'tableName'