其他分享
首页 > 其他分享> > Hbase高级功能过滤(Filter)

Hbase高级功能过滤(Filter)

作者:互联网

1.创建一个Rumenz

// 创建了两个列族user和depart
> ./bin/hbase shell
> create 'Rumenz','user','depart'

2.插入数据

> put 'Rumenz','user|id1','user:name','张三'
> put 'Rumenz','user|id1','depart:name','开发部'
> put 'Rumenz','user|id2','user:name','王五'
> put 'Rumenz','user|id2','depart:name','市场部'
> put 'Rumenz','user|tsc','user:name','入门'
> put 'Rumenz','user1|id1','user:name','小站'

3.找出值为张三的记录

> scan 'Rumenz',FILTER=>"ValueFilter(=,'binary:张三')"

4.找出值中包含字的记录

> scan 'Rumenz',FILTER=>"ValueFilter(=,'substring:部')"

5.找出列名以dep开头的记录

> scan 'Rumenz',FILTER=>"ColumnPrefixFilter('dep')"

6.找出列名以ts开头并且值为入门的值

> scan 'Rumenz',FILTER=>"ColumnPrefixFilter('ts') AND ValueFilter(=,'binary:入门')"

7.找出rowkey以user1开头

> scan 'Rumenz',FILTER=>"PrefixFilter('user1')"

8.一个rowkey可能有会多个版本,通过FirstKeyOnlyFilter可以获取最新版本的数据.获取最新数据中值中包含的数据

> scan 'Rumenz',FILTER=>"FirstKeyOnlyFilter() and ValueFilter(=,'substring:部')"

9.一个rowkey可能有会多个版本,通过FirstKeyOnlyFilter可以获取最新版本的数据.获取最新数据中值中包含的数据并且只返回key不需要value

> scan 'Rumenz',FILTER=>"FirstKeyOnlyFilter() and ValueFilter(=,'substring:部') AND KeyOnlyFilter()"

10.从user|id2行开始,查询rowkey以user开头的数据

> sacn 'Rumenz',{STARTROW=>'user|id2',FILTER=>"PrefixFilter('user')"}

11.查找rowkey中包含id的数据

> scan 'Rumenz', {FILTER => RowFilter.new(CompareFilter::CompareOp.valueOf('EQUAL'), SubstringComparator.new('id'))}

12.查找user:name列值为王五的数据并只显示user:name

//显示多个列使用COLUMNS => ['user:name','xxxx']
>scan 'Rumenz', {COLUMNS => 'user:name', FILTER => SingleColumnValueFilter.new(Bytes.toBytes('u

标签:FILTER,Rumenz,name,scan,Filter,过滤,user,put,Hbase
来源: https://blog.csdn.net/w892824196/article/details/120368036