使用HBase外壳进行扫描 [英] Scan with filter using HBase shell
本文介绍了使用HBase外壳进行扫描的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有人知道如何根据扫描过滤器扫描记录,即:
column:something =somevalue
类似于此,但是来自HBase shell?
解决方案
试试这个。这是一种丑陋的,但它适用于我。
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 shell将包括〜/ .irbrc中的任何内容,所以你可以在这里放入类似的东西(我不是Ruby专家,欢迎改进):
#像以上一样导入
def scan_substr(表,家庭,限定符,substr,* cols)
扫描表,{COLUMNS => cols,FILTER =>
SingleColumnValueFilter.new
(Bytes.toBytes(family),Bytes.toBytes(qualifier),
CompareFilter :: CompareOp.valueOf('EQUAL'),
SubstringComparator.new substr))}
end
然后你可以在shell中说:
scan_substr't1','family','qualifier','somevalue','family:qualifier'
Does anybody know how to scan records based on some scan filter i.e.:
column:something = "somevalue"
Something like this, but from HBase shell?
解决方案
Try this. It's kind of ugly, but it works for me.
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'))
}
The HBase shell will include whatever you have in ~/.irbrc, so you can put something like this in there (I'm no Ruby expert, improvements are welcome):
# 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
and then you can just say in the shell:
scan_substr 't1', 'family', 'qualifier', 'somevalue', 'family:qualifier'
这篇关于使用HBase外壳进行扫描的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文