Database Reference
In-Depth Information
scanner.close();
table.close();
}
}
SingleColumnValueFilter and SingleColumnValueExcludedFilter :
These ilters keep track of a single column value, which if it exists, makes
the row eligible to either be included or excluded from the results. It takes
a CompareFilter.CompareOp operator (equal, greater, not equal, and so on)
and either a byte[] value or ByteArrayComparable . Also, it takes a family
and a qualiier, as shown in the following code:
public class SCVFilterExample {
public static void main(String[] args) throws IOException
{
// Get instance of Default Configuration
Configuration conf = HBaseConfiguration.create();
// Get table instance
HTable table = new HTable(conf, "tab1");
SingleColumnValueFilter filter = new
SingleColumnValueFilter(
Bytes.toBytes("cf1"), Bytes.toBytes("greet"),
CompareFilter.CompareOp.EQUAL, new
SubstringComparator("Hello"));
// By Default it is false.
// If set as true, this restricts the rows
// if the specified column is not present
filter.setFilterIfMissing(true);
// Create Scan instance
Scan scan = new Scan();
scan.setFilter(filter);
// Get Scanner Results
ResultScanner scanner = table.getScanner(scan);
for (Result res : scanner) {
System.out.println("Row Value: " + res);
}
scanner.close();
table.close();
}
}
 
Search WWH ::




Custom Search