Hbase高级功能过滤(Filter)

1.创建一个Rumenz

  1. // 创建了两个列族user和depart
  2. create 'Rumenz','user','depart'

2.插入数据

  1. > put 'Rumenz','user|id1','user:name','张三'
  2. > put 'Rumenz','user|id1','depart:name','开发部'
  3. > put 'Rumenz','user|id2','user:name','王五'
  4. > put 'Rumenz','user|id2','depart:name','市场部'
  5. > put 'Rumenz','user|tsc','user:name','入门'
  6. > put 'Rumenz','user1|id1','user:name','小站'

2.找出值为张三的记录

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

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

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

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

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

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

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

6.找出rowkey以user1开头

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

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

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

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

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

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

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

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

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

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

  1. //显示多个列使用COLUMNS => ['user:name','xxxx']
  2. >scan 'Rumenz', {COLUMNS => 'user:name', FILTER => SingleColumnValueFilter.new(Bytes.toBytes('user'), Bytes.toBytes('name'), CompareFilter::CompareOp.valueOf('EQUAL'), Bytes.toBytes('王五'))}
返回笔记列表
入门小站