./hbase shell
help
help “get” #查看单独的某个命令的帮助
create ‘表名称’,’列名称1’,’列名称2’,’列名称3’
如:
create 'member','member_id','address','info'
list ‘abc.*’ #显示abc开头的表
Table play_error_file is ENABLED
play_error_file
column families description
{
NAME => 'cf',
BLOOMFILTER => 'ROW',#根据应用来定,看需要精确到rowkey还是column。bloom filter的作用是对一个region下查找记录所在的hfile有用。一个region下hfile数量越多,bloom filter的作用越明显。适合那种compaction(压缩)赶不上flush速度的应用。
VERSIONS => '1',# 通常是3,对于更新比较频繁的应用可以设置为1
IN_MEMORY => 'false',
KEEP_DELETED_CELLS => 'FALSE',
DATA_BLOCK_ENCODING => 'NONE',
TTL => 'FOREVER',
COMPRESSION => 'NONE',
MIN_VERSIONS => '0',
BLOCKCACHE =>'true',
BLOCKSIZE => '65536',
REPLICATION_SCOPE => '0'
}
disable 'member' #删除列族时必须先将表给disable
alter 'member',{NAME=>'member_id',METHOD=>'delete'}
#删除后继续enable 'member'
enable 'member'
disable 'table_name'
drop 'table_name'
exists 'table_name'
is_enabled 'table_name'
//快照 这样试试,先建立个表自己测试下,可以的话在执行。
需要开启快照功能,在hbase-site.xml文件中添加如下配置项:
hbase.snapshot.enabled
true
//命令
hbase shell> disable 'tableName'
hbase shell> snapshot 'tableName', 'tableSnapshot'
hbase shell> clone_snapshot 'tableSnapshot', 'newTableName'
hbase shell> delete_snapshot 'tableSnapshot'
hbase shell> drop 'tableName'
在ns1:t1或者t1表里的r1行,c1列中插入值,ts1是时间
put 'ns1:t1', 'r1','c1','value'
or
put 't1','r1','c1','value'
or
put 't1','r1','c1','value',ts1
or
put 't1','r1','c1','value',{ATTRIBUTES=>{'mykey'=>'myvalue'}}
put 't1','r1','c1','value',ts1,{ATTRIBUTES=>{'mykey'=>'myvalue'}}
put 't1','r1','c1','value',ts1,{VISIBILITY=>'PRIVATE|SECRET}
# t是table 't1'表的引用
t.put 'r1','c1','value',ts1,{ATTRIBUTES=>{'mykey'=>'myvalue'}}
put 'table_name','row_index','info:age','24'
put 'table_name','row_index','info:birthday','1987-06-17'
put 'table_name','row_index','info:company','tencent'
put 'table_name','row_index','address:contry','china'
put 'table_name','row_index','address:province','china'
put 'table_name','row_index','address:city','shenzhen'
# 获取一个id的所有数据
get 'table_name','row_index'
# 获取一个id,一个列族的所有数据
get 'table_name','row_index','info'
# 获取一个id,一个列族中一个列的所有数据
get 'table_name','row_index','info:age'
将qy的单位改为qq
put ‘table_name’,’qy’,’info:company’,’qq’
# 得到company为tencent的记录
get 'table_name','qy',{COLUMN=>'info:company',TIMESTRAP=>1321586238965}
# 得到company为qq的数据
get 'table_name','qy',{COLUMN=>'info:company',TIMESTRAP=>1321586271843}
scanner规范:
TIMERANGE,
FILTER,
LIMIT,
STARTROW(start row),
STOPROW(stop row),
ROWPREFIXFILTER(row prefix filter,行前缀)
TIMESTAMP,
MAXLENGTH,
or COLUMNS,
CACHE,
or RAW,
VERSIONS
scan 'hbase:meta'
scan 'hbase:meta',{COLUMNS => 'info:regioninfo'}
scan 'ns1:t1',{COLUMNS=>['c1','c2'],LIMIT=>10,STARTROW=>'xyz'}
scan 't1',{COLUMNS=>'c1',TIMERANGE=>[1303668804,1303668904]}
scan 't1',{REVERSED=>true}
scan 't1',{
ROWPREFIXFILTER=>'row2',
FILTER=>"(QualifierFilter(>=,'binary:xyz'))
AND (TimestampsFilter(123,456))"}
scan 't1',{FILTER => org.apache.hadoop.hbase.filter.ColumnPaginationFilter.new(1,0)}
scan 't1',{CONSISTENCY=>'TIMELINE'}
设置操作属性:
scan 't1',{COLUMNS => ['c1','c2'],ATTRIBUTES=>{'mykey'=>'myvalue'}}
scan 't1',{COLUMNS=>['c1','c2'],AUTHORIZATIONS=>['PRIVATE','SECRET']}
有个额外的选项:CACHE_BLOCKS,默认为true
还有个选项:RAW,返回所有cells(包括删除的markers和uncollected deleted cells,不能用来选择特定的columns,默认为default)
如:scan 't1',{RAW=>true,VERSIONS=>10}
全表扫描一般不会用,数据量大的时候会死人的。。
# 删除id为temp的记录的'info:age'字段
delete 'member','temp','info:age'
# 删除整行
deleteall 'member','temp'
count 'table_name',INTERVAL=>1000,CACHE => 1000
or
有对表t1的引用t
t.count
INTERVAL: 每隔多少行显示一次count,默认是1000
CACHE:每次去取的缓存区大小,默认是10,调整该参数可提高查询速度
truncate 'table_name'
HBase是先将表disable,再drop the table,最后creating table。
scan ‘qy’,{COLUMNS=>’name’}
scan ‘qy’,{COLUMNS=>’name:gender’}
scan ‘qy’,{COLUMNS=>[‘name’,’foo’]}
限制查找条数:
scan ‘qy’,{COLUMNS=>[‘name’,’foo’],LIMIT=>1}
scan ‘qy’,{COLUMNS=>[‘name’,’foo’],LIMIT=>2}
限制时间范围:
scan ‘qy’,{TIMERANGE=>[1448045892646,1448045892647]}
PrefixFilter:rowKey前缀过滤
scan ‘qy’,{FILTER=>”PrefixFilter(‘001’)”}
scan ‘qy’,{FILTER=>PrefixFilter(‘t’)}
QualifierFilter:列过滤器
QualifierFilter对列的名称进行过滤,而不是列的值。
scan ‘qy’,{FILTER=>”PrefixFilter(‘t’) AND QualifierFilter(>=,’binary:b’)”}
TimestampsFilter:时间戳过滤器
scan ‘qy’,{FILTER=>”TimestampsFilter(1448069941270,1548069941230)” }
scan ‘qy’,{FILTER=>”(QualifierFilter(>=,’binary:b’)) AND (TimestampsFilter(1348069941270,1548069941270))” }
ColumnPaginationFilter
scan ‘qy’,{FILTER=>org.apache.hbase.filter.ColumnPaginationFilter.new(2,0)}
cannot load Java class org.apache.hbase.filter.ColumnPaginationFilter
hbase shell应用filter
1.导入需要的类
import org.apache.hadoop.hbase.filter.CompareFilter
import org.apache.hadoop.hbase.filter.SingleColumnValueFilter
import org.apache.hadoop.hbase.filter.SubstringComparator
import org.apache.hadoop.hbase.util.Bytes
2.执行命令
scan 'tablename',STARTROW=>'start',COLUMNS=>['family:qualifier'],FILTER=>SingleColumnValueFilter.new(Bytes.toBytes('family'),Bytes.toBytes('qualifier'))
https://blog.csdn.net/power0405hf/article/details/49824579