// 1. got rows > "row4"
Filter rowFilter = new RowFilter(CompareOp.GREATER, new BinaryComparator(
Bytes.toBytes("row4")));
Scan s1 = new Scan();
s1.setFilter(rowFilter);
InternalScanner scanner = testRegion.getScanner(s1);
List<KeyValue> results = new ArrayList<KeyValue>();
int i = 5;
for (boolean done = true; done; i++) {
done = scanner.next(results);
Assert.assertTrue(Bytes.equals(results.get(0).getRow(), Bytes.toBytes("row" + i)));
Assert.assertEquals(Bytes.toInt(results.get(0).getValue()), i%2);
results.clear();
}
// 2. got rows <= "row4" and S=
FilterList subFilterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);
Filter subFilter1 = new RowFilter(CompareOp.LESS_OR_EQUAL, new BinaryComparator(
Bytes.toBytes("row4")));
subFilterList.addFilter(subFilter1);
Filter subFilter2 = new SingleColumnValueFilter(FAMILIES[0], columnStatus, CompareOp.EQUAL,
Bytes.toBytes(0));
subFilterList.addFilter(subFilter2);
s1 = new Scan();
s1.setFilter(subFilterList);
scanner = testRegion.getScanner(s1);
results = new ArrayList<KeyValue>();
for (i=0; i<=4; i+=2) {
scanner.next(results);
Assert.assertTrue(Bytes.equals(results.get(0).getRow(), Bytes.toBytes("row" + i)));
Assert.assertEquals(Bytes.toInt(results.get(0).getValue()), i%2);
results.clear();
}
Assert.assertFalse(scanner.next(results));
// 3. let's begin to verify nested filter list
// 3.1 add rowFilter, then add subFilterList
FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ONE);
filterList.addFilter(rowFilter);
filterList.addFilter(subFilterList);
s1 = new Scan();
s1.setFilter(filterList);
scanner = testRegion.getScanner(s1);
results = new ArrayList<KeyValue>();
for (i=0; i<=4; i+=2) {
scanner.next(results);
Assert.assertTrue(Bytes.equals(results.get(0).getRow(), Bytes.toBytes("row" + i)));
Assert.assertEquals(Bytes.toInt(results.get(0).getValue()), i%2);
results.clear();
}
for (i=5; i<=9; i++) {
scanner.next(results);
Assert.assertTrue(Bytes.equals(results.get(0).getRow(), Bytes.toBytes("row" + i)));
Assert.assertEquals(Bytes.toInt(results.get(0).getValue()), i%2);
results.clear();
}
Assert.assertFalse(scanner.next(results));
// 3.2 MAGIC here! add subFilterList first, then add rowFilter
filterList = new FilterList(FilterList.Operator.MUST_PASS_ONE);
filterList.addFilter(subFilterList);
filterList.addFilter(rowFilter);
s1 = new Scan();
s1.setFilter(filterList);
scanner = testRegion.getScanner(s1);
results = new ArrayList<KeyValue>();
for (i=0; i<=4; i+=2) {
scanner.next(results);
Assert.assertTrue(Bytes.equals(results.get(0).getRow(), Bytes.toBytes("row" + i)));
Assert.assertEquals(Bytes.toInt(results.get(0).getValue()), i%2);
results.clear();
}
for (i=5; i<=9; i++) {
scanner.next(results);
Assert.assertTrue(Bytes.equals(results.get(0).getRow(), Bytes.toBytes("row" + i)));
Assert.assertEquals(Bytes.toInt(results.get(0).getValue()), i%2);
results.clear();
}
Assert.assertFalse(scanner.next(results));
HLog hlog = testRegion.getLog();
testRegion.close();
hlog.closeAndDelete();
}