doing a ValueFilter or a ColumnFilter on hbase shell

喜你入骨 提交于 2019-12-19 09:54:16

问题


Could anyone please tell me how to do a qualifier filter or ValueFilter from the hbase shell command line?


回答1:


It is very similar to how you would code in any programming language, for instance :-

import org.apache.hadoop.hbase.filter.CompareFilter
import org.apache.hadoop.hbase.filter.SingleColumnValueFilter
import org.apache.hadoop.hbase.util.Bytes
scan 'tableName', {COLUMNS=>['CF:qualifier1', 'CF:qualifier2'], LIMIT=>10,
FILTER=>SingleColumnValueFilter.new(Bytes.toBytes('CF'),
Bytes.toBytes('qualifier1'), CompareFilter::CompareOp.valueOf('EQUAL'),
Bytes.toBytes('value'))}

You obviously have to change parameters depending on the fiter you use.




回答2:


You can instantiate any filter the same way you would do in Java (with JRuby syntax), and supply the filter as:

filter = ...
scan 'mytable', FILTER => filter

However, instantiating the filter in the shell directly can be cumbersome, so an easier way is to supply filter as a string using Filter Language. For example, to include all the columns with value equal to 'myvalue' in a scan you would use:

scan 'mytable', FILTER => "ValueFilter(=, 'binary:myvalue')

You can check this document as a 'Filter Language' reference.




回答3:


Additionally, to scan a specific column for a substring you can do:

scan 'myTable', { COLUMNS => 'cf:abc', FILTER => "ValueFilter(=, 'substring:myvalue')"}


来源:https://stackoverflow.com/questions/12634321/doing-a-valuefilter-or-a-columnfilter-on-hbase-shell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!