简体   繁体   中英

Hbase filter a column with list of values

How can i pass a list of values to a SingleColumnFilter for an hbase scan and query ?

val ListOfID = List("ID1","ID2",...,"ID15",...,"ID150") 

I know how to filter for one value :

val IDFilter = new SingleColumnValueFilter(Bytes.toBytes("header"), Bytes.toBytes("ID"), CompareFilter.CompareOp.EQUAL, Bytes.toBytes(String.valueOf(ID)))

But i would like to pass a list of value to the filter, because my list has more than 150 elements.

Thanks in advance

Here is a solution i found, with RegexStringComparator it works, but i don't know if its the best that can be done :

val ListOfID = List("ID1","ID2",...,"ID15",...,"ID150") 
val IDListString = ListOfID.mkString("|")

val scan = new Scan


val IDFilter = new SingleColumnValueFilter(Bytes.toBytes("header"), Bytes.toBytes("networkIdentifier"), CompareFilter.CompareOp.EQUAL,new RegexStringComparator(IDListString))

val filters = new FilterList(IDFilter)    
scan.setFilter(filters)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM