use of org.apache.hadoop.hbase.regionserver.InternalScanner in project hbase by apache.
the class TestFilter method testWhileMatchFilterWithFilterRow.
/**
* Tests the the {@link WhileMatchFilter} works in combination with a
* {@link Filter} that uses the
* {@link Filter#filterRow()} method.
*
* See HBASE-2258.
*
* @throws Exception
*/
@Test
public void testWhileMatchFilterWithFilterRow() throws Exception {
final int pageSize = 4;
Scan s = new Scan();
WhileMatchFilter filter = new WhileMatchFilter(new PageFilter(pageSize));
s.setFilter(filter);
InternalScanner scanner = this.region.getScanner(s);
int scannerCounter = 0;
while (true) {
boolean isMoreResults = scanner.next(new ArrayList<>());
scannerCounter++;
if (scannerCounter >= pageSize) {
assertTrue("The WhileMatchFilter should now filter all remaining", filter.filterAllRemaining());
}
if (!isMoreResults) {
break;
}
}
assertEquals("The page filter returned more rows than expected", pageSize, scannerCounter);
}
use of org.apache.hadoop.hbase.regionserver.InternalScanner in project hbase by apache.
the class TestFilterFromRegionSide method testFirstKeyOnlyFilterAndBatch.
@Test
public void testFirstKeyOnlyFilterAndBatch() throws IOException {
Scan scan = new Scan();
scan.setFilter(new FirstKeyOnlyFilter());
scan.setBatch(1);
InternalScanner scanner = REGION.getScanner(scan);
List<Cell> results = new ArrayList<>();
for (int i = 0; i < NUM_ROWS; i++) {
results.clear();
scanner.next(results);
assertEquals(1, results.size());
Cell cell = results.get(0);
assertArrayEquals(ROWS[i], Bytes.copy(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()));
}
assertFalse(scanner.next(results));
scanner.close();
}
use of org.apache.hadoop.hbase.regionserver.InternalScanner in project hbase by apache.
the class TestFilterFromRegionSide method testFirstSeveralCellsFilterAndBatch.
@Test
public void testFirstSeveralCellsFilterAndBatch() throws IOException {
Scan scan = new Scan();
scan.setFilter(new FirstSeveralCellsFilter());
scan.setBatch(NUM_COLS);
InternalScanner scanner = REGION.getScanner(scan);
List<Cell> results = new ArrayList<>();
for (int i = 0; i < NUM_ROWS; i++) {
results.clear();
scanner.next(results);
assertEquals(NUM_COLS, results.size());
Cell cell = results.get(0);
assertArrayEquals(ROWS[i], Bytes.copy(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()));
assertArrayEquals(FAMILIES[0], Bytes.copy(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength()));
assertArrayEquals(QUALIFIERS[0], Bytes.copy(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()));
}
assertFalse(scanner.next(results));
scanner.close();
}
use of org.apache.hadoop.hbase.regionserver.InternalScanner in project hbase by apache.
the class TestFilter method testWhileMatchFilterWithFilterRowKeyWithReverseScan.
@Test
public void testWhileMatchFilterWithFilterRowKeyWithReverseScan() throws Exception {
Scan s = new Scan();
String prefix = "testRowOne";
WhileMatchFilter filter = new WhileMatchFilter(new PrefixFilter(Bytes.toBytes(prefix)));
s.setFilter(filter);
s.setReversed(true);
InternalScanner scanner = this.region.getScanner(s);
while (true) {
ArrayList<Cell> values = new ArrayList<>();
boolean isMoreResults = scanner.next(values);
if (!isMoreResults || !Bytes.toString(CellUtil.cloneRow(values.get(0))).startsWith(prefix)) {
Assert.assertTrue("The WhileMatchFilter should now filter all remaining", filter.filterAllRemaining());
}
if (!isMoreResults) {
break;
}
}
scanner.close();
}
use of org.apache.hadoop.hbase.regionserver.InternalScanner in project hbase by apache.
the class TestFilter method testWhileMatchFilterWithFilterRowKey.
/**
* Tests the the {@link WhileMatchFilter} works in combination with a
* {@link Filter} that uses the
* {@link Filter#filterRowKey(Cell)} method.
*
* See HBASE-2258.
*
* @throws Exception
*/
@Test
public void testWhileMatchFilterWithFilterRowKey() throws Exception {
Scan s = new Scan();
String prefix = "testRowOne";
WhileMatchFilter filter = new WhileMatchFilter(new PrefixFilter(Bytes.toBytes(prefix)));
s.setFilter(filter);
InternalScanner scanner = this.region.getScanner(s);
while (true) {
ArrayList<Cell> values = new ArrayList<>();
boolean isMoreResults = scanner.next(values);
if (!isMoreResults || !Bytes.toString(CellUtil.cloneRow(values.get(0))).startsWith(prefix)) {
assertTrue("The WhileMatchFilter should now filter all remaining", filter.filterAllRemaining());
}
if (!isMoreResults) {
break;
}
}
}
Aggregations