2011-08-31 7 views

Trả lời

46

Hãy thử điều này. Đó là loại xấu xí, nhưng nó làm việc cho tôi.

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')) 
} 

Vỏ HBase sẽ bao gồm bất cứ điều gì bạn có trong ~/.irbrc, vì vậy bạn có thể đặt một cái gì đó như thế này trong đó (Tôi không phải chuyên gia Ruby, cải tiến được hoan nghênh):

# 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 

và sau đó bạn chỉ có thể nói trong vỏ:

scan_substr 't1', 'family', 'qualifier', 'somevalue', 'family:qualifier' 
+0

Điều này thực sự là siêu xấu xí. Cảm ơn mặc dù, không thể tìm thấy bất kỳ ví dụ về điều này trong sách HBase docs/book/oreilly. – mumrah

8

Sử dụng param LỌC của scan, như thể hiện trong sự giúp đỡ sử dụng:

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} 
28
scan 'test', {COLUMNS => ['F'],FILTER => \ 
"(SingleColumnValueFilter('F','u',=,'regexstring:http:.*pdf',true,true)) AND \ 
(SingleColumnValueFilter('F','s',=,'binary:2',true,true))"} 

thông tin có thể tìm thêm here. Lưu ý rằng nhiều ví dụ nằm trong tệp đính kèm Filter Language.docx.

+0

Tôi nghĩ rằng ngôn ngữ này phân tích cú pháp lọc chỉ làm việc trong các phiên bản sau của HBase - trong 0.90.6 (cdh 3u6) Tôi không thể nhận được bất kỳ biến thể này để làm việc. – Mikeb

+0

Tôi nghĩ rất hữu ích khi nhìn vào javadoc; đây là javadoc cho 0,94: http://hbase.apache.org/0.94/apidocs/org/apache/hadoop/hbase/filter/SingleColumnValueFilter.html – mooreds

6
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); 
+0

Mã này bằng Java, câu hỏi đặt ra là hỏi về vỏ HBase. – Tony

3

Một trong những bộ lọc là Valuefilter mà có thể được sử dụng để lọc tất cả các giá trị cột.

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

nhị phân là một trong những bộ so sánh được sử dụng trong bộ lọc. Bạn có thể sử dụng các bộ so sánh khác nhau trong bộ lọc dựa trên những gì bạn muốn làm.

Bạn có thể tham khảo url sau: http: // www.hadooptpoint.com/filters-in-hbase-shell/. Nó cung cấp các ví dụ tốt về cách sử dụng các bộ lọc khác nhau trong HBase Shell.

+0

Chỉ liên kết câu trả lời không phải là câu hỏi hay. Đăng một số mã và giải thích nó để giúp đỡ. – KittMedia