Brooklyn Knightley
Brooklyn Knightley

Reputation: 345

How to combine filters in Hbase shell?

I wanna select some rows from hbase table, how to set multifilters? It seems that AND doesn't work. I have tried two ways.

scan 'hbase_table', { FILTER => "(RowFilter(=, 'regexstring:39$') AND SingleColumnValueFilter ('binary:family','binary:qualifier', '=', 'value')" }

or

scan 'hbase_table', {LIMIT => 10, FILTER => "(RowFilter.new(CompareFilter::CompareOp.valueOf('EQUAL'), RegexStringComparator.new("39$")) AND SingleColumnValueFilter.new(Bytes.toBytes('family'), Bytes.toBytes('qualifier'), CompareFilter::CompareOp.valueOf('EQUAL'), Bytes.toBytes('value')))", COLUMNS => 'family:qualifier'}

many thanks

Upvotes: 5

Views: 9133

Answers (3)

Jacob Joy
Jacob Joy

Reputation: 556

Using only SingleColumnValueFilter

scan 'table', {FILTER => "SingleColumnValueFilter
    ('columnfamily', 'columnname', =, 'binary:value', true, false) 
AND SingleColumnValueFilter('columnfamily', 'columnname', =, 'binary:value', true, false)"}

Replace following fields,

table - hbase table name ex: hbaseTemp

columnfamily - hbase column family name ex: s

columnname - hbase column name ex: id

value - hbase field value ex: 12343

Docx for SingleColumnValueFilter: https://hbase.apache.org/apidocs/org/apache/hadoop/hbase/filter/SingleColumnValueFilter.html

Upvotes: 1

maicalal
maicalal

Reputation: 101

This question was asked long back, but just in case it helps someone...

I have tried combining prefixfilter and SingleColumnValueFilter like below and it works as expected:

scan 'dbtest:table1', {FILTER => "(PrefixFilter ('abc') AND SingleColumnValueFilter('cf','age',>=, 'binary:10',true,false)"}

Here

  • dbtest is my namespace, if its default for you then you can skip
  • cf is my column family
  • age is a column
  • This should result in rows having 'abc' as prefix and 'cf:age' column value >= 10

This link should help understand the filters better

Upvotes: 1

Ramzy
Ramzy

Reputation: 7138

The first command is correct. Can you try individual filters and see if they are working fine. Then try with AND. This can help you if needed

Upvotes: 3

Related Questions