HBASE & Java: Scan Filters

This tutorial will guide you through how to use filtering when scanning a HBASE table using Java 8. Make sure you first follow this tutorial on connecting to HBASE and this tutorial on scanning HBase.

Row Key Filter (PrefixFilter):

final PrefixFilter prefixFilter = new PrefixFilter(Bytes.toBytes(myRoKey));
scan.addFilter(prefixFilter);

Column Value Filter:

final SingleColumnValueFilter columnValueFilter = new SingleColumnValueFilter(myColumnFamily, myColumnName, CompareOp.EQUAL, Bytes.toBytes(myValue));
scan.addFilter(columnValueFilter);

Regex Filter:

final RegexStringComparator regexStringComparator = new RegexStringComparator(".*");
final SingleColumnValueFilter singleColumnValueFilter = new SingleColumnValueFilter(myColumnFamily, myColumnName, CompareOp.EQUAL, regexStringComparator);
scan.addFilter(singleColumnValueFilter);