回答
试试这个。这有点丑陋,但它适用于我。
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
scan 't1', { COLUMNS => 'family:qualifier', FILTER =>
SingleColumnValueFilter.new
(Bytes.toBytes('family'),
Bytes.toBytes('qualifier'),
CompareFilter::CompareOp.valueOf('EQUAL'),
SubstringComparator.new('somevalue'))
}
HBase的外壳将包括无论你在〜/ .irbrc,所以你可以把这样的事情在那里(我不是红宝石的专家,改进欢迎):
# imports like above
def scan_substr(table,family,qualifier,substr,*cols)
scan table, { COLUMNS => cols, FILTER =>
SingleColumnValueFilter.new
(Bytes.toBytes(family), Bytes.toBytes(qualifier),
CompareFilter::CompareOp.valueOf('EQUAL'),
SubstringComparator.new(substr)) }
end
然后你可以说,在外壳:
scan_substr 't1', 'family', 'qualifier', 'somevalue', 'family:qualifier'
使用的过滤特性参数的scan
,如图所示用法帮助:
hbase(main):002:0> scan
ERROR: wrong number of arguments (0 for 1)
Here is some help for this command:
Scan a table; pass table name and optionally a dictionary of scanner
specifications. Scanner specifications may include one or more of:
TIMERANGE, FILTER, LIMIT, STARTROW, STOPROW, TIMESTAMP, MAXLENGTH,
or COLUMNS. If no columns are specified, all columns will be scanned.
To scan all members of a column family, leave the qualifier empty as in
'col_family:'.
Some examples:
hbase> scan '.META.'
hbase> scan '.META.', {COLUMNS => 'info:regioninfo'}
hbase> scan 't1', {COLUMNS => ['c1', 'c2'], LIMIT => 10, STARTROW => 'xyz'}
hbase> scan 't1', {FILTER => org.apache.hadoop.hbase.filter.ColumnPaginationFilter.new(1, 0)}
hbase> scan 't1', {COLUMNS => 'c1', TIMERANGE => [1303668804, 1303668904]}
For experts, there is an additional option -- CACHE_BLOCKS -- which
switches block caching for the scanner on (true) or off (false). By
default it is enabled. Examples:
hbase> scan 't1', {COLUMNS => ['c1', 'c2'], CACHE_BLOCKS => false}
scan 'test', {COLUMNS => ['F'],FILTER => \
"(SingleColumnValueFilter('F','u',=,'regexstring:http:.*pdf',true,true)) AND \
(SingleColumnValueFilter('F','s',=,'binary:2',true,true))"}
更多信息,可以发现here。请注意,附件Filter Language.docx
文件中有多个示例。
Scan scan = new Scan();
FilterList list = new FilterList(FilterList.Operator.MUST_PASS_ALL);
//in case you have multiple SingleColumnValueFilters,
you would want the row to pass MUST_PASS_ALL conditions
or MUST_PASS_ONE condition.
SingleColumnValueFilter filter_by_name = new SingleColumnValueFilter(
Bytes.toBytes("SOME COLUMN FAMILY"),
Bytes.toBytes("SOME COLUMN NAME"),
CompareOp.EQUAL,
Bytes.toBytes("SOME VALUE"));
filter_by_name.setFilterIfMissing(true);
//if you don't want the rows that have the column missing.
Remember that adding the column filter doesn't mean that the
rows that don't have the column will not be put into the
result set. They will be, if you don't include this statement.
list.addFilter(filter_by_name);
scan.setFilter(list);
这段代码是用Java编写的,问题在于询问HBase shell。 – Tony
其中一个过滤器的是Valuefilter可用于过滤所有列的值。
hbase(main):067:0> scan 'dummytable', {FILTER => "ValueFilter(=,'binary:2016-01-26')"}
二进制是过滤器内所使用的比较器之一。根据你想要做的事情,你可以在过滤器中使用不同的比较器。
您可以参考以下url:http:// www.hadooptpoint.com/filters-in-hbase-shell/. 它提供了有关如何在HBase Shell中使用不同过滤器的很好示例。
链接只有答案不是很好的问题。发布一些代码并解释它以提供帮助。 – KittMedia
- 1. mapreduce,hbase和扫描
- 2. 外壳脚本端口扫描器
- 3. 扫描特定rowkey的Hbase
- 4. 使用HBase API(Java)扫描筛选器
- 5. HBase扫描 - RowKey过滤器
- 6. HBase扫描操作缓存
- 7. 如何扫描HBase的数值范围
- 8. Hbase vs Google Bigtable:扫描大量的行
- 9. 对“C”源程序中的变量进行外壳扫描
- 10. HBASE行前缀扫描以相反的顺序在HBase的
- 11. 如何做hbase范围扫描?
- 12. 扫描hbase时,地图任务卡住
- 13. Hbase客户端扫描程序挂起
- 14. 如何做HBase部分扫描?
- 15. 如何改进HBase扫描仪?
- 16. 从hbase shell中获取扫描结果
- 17. HBase Mapreduce在多个扫描对象上
- 18. HBase行键和范围扫描
- 19. 使用扫描
- 20. 在远程HBase上使用Camel进行表扫描
- 21. 注释扫描不扫描类路径中的外部罐子
- 22. 外部指纹扫描仪
- 23. 使用FilterExpression进行Dynamodb扫描()使用FilterExpression进行Dynamodb扫描()
- 24. 使用扫描仪的Java
- 25. 文本框中的扫描值(使用扫描仪)
- 26. 这是使用扫描仪扫描多个输入的方式
- 27. 使用扫描仪扫描图像的Java库
- 28. TCP空扫描使用Scapy
- 29. 使用Java扫描WiFi WiFi
- 30. structuremap使用objectfactory.initialize扫描,也
这确实是超级丑陋的。不过谢谢,在HBase docs/book/oreilly书中找不到这样的例子。 – mumrah