使用HBase shell扫描过滤器

Gan*_*row 43 hbase nosql

有人知道如何根据某些扫描过滤器扫描记录,即:

column:something = "somevalue"

这样的东西,但来自HBase shell?

bha*_*nki 47

试试这个.这有点难看,但对我有用.

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'))
}
Run Code Online (Sandbox Code Playgroud)

HBase shell将包含〜/ .irbrc中的任何内容,因此您可以在其中放置类似的东西(我不是Ruby专家,欢迎改进):

# 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
Run Code Online (Sandbox Code Playgroud)

然后你可以在shell中说:

scan_substr 't1', 'family', 'qualifier', 'somevalue', 'family:qualifier'
Run Code Online (Sandbox Code Playgroud)


dap*_*ape 29

scan 'test', {COLUMNS => ['F'],FILTER => \ 
"(SingleColumnValueFilter('F','u',=,'regexstring:http:.*pdf',true,true)) AND \
(SingleColumnValueFilter('F','s',=,'binary:2',true,true))"}
Run Code Online (Sandbox Code Playgroud)

更多信息可以在这里找到.请注意,附加Filter Language.docx文件中包含多个示例.


Ton*_*ony 8

使用FILTER参数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}
Run Code Online (Sandbox Code Playgroud)


Kan*_*rKK 5

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);
Run Code Online (Sandbox Code Playgroud)

  • 这段代码是用 Java 编写的,问题是关于 HBase shell。 (2认同)

Che*_*ani 5

过滤器之一是Valuefilter,可用于过滤所有列值。

hbase(main):067:0> scan 'dummytable', {FILTER => "ValueFilter(=,'binary:2016-01-26')"}

二进制是滤波器中使用的比较器之一。您可以根据需要在过滤器中使用不同的比较器。

您可以参考以下网址:http://www.hadooptpoint.com/filters-in-hbase-shell/。 它提供了有关如何在HBase Shell中使用不同过滤器的良好示例。