Search in sources :

Example 31 with InternalScanner

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);
}
Also used : InternalScanner(org.apache.hadoop.hbase.regionserver.InternalScanner) Scan(org.apache.hadoop.hbase.client.Scan) Test(org.junit.Test)

Example 32 with InternalScanner

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();
}
Also used : InternalScanner(org.apache.hadoop.hbase.regionserver.InternalScanner) ArrayList(java.util.ArrayList) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 33 with InternalScanner

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();
}
Also used : InternalScanner(org.apache.hadoop.hbase.regionserver.InternalScanner) ArrayList(java.util.ArrayList) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 34 with InternalScanner

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();
}
Also used : InternalScanner(org.apache.hadoop.hbase.regionserver.InternalScanner) ArrayList(java.util.ArrayList) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 35 with InternalScanner

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;
        }
    }
}
Also used : InternalScanner(org.apache.hadoop.hbase.regionserver.InternalScanner) ArrayList(java.util.ArrayList) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Aggregations

InternalScanner (org.apache.hadoop.hbase.regionserver.InternalScanner)44 ArrayList (java.util.ArrayList)41 Cell (org.apache.hadoop.hbase.Cell)36 Scan (org.apache.hadoop.hbase.client.Scan)34 Test (org.junit.Test)17 IOException (java.io.IOException)15 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)12 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)12 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)9 Put (org.apache.hadoop.hbase.client.Put)9 List (java.util.List)7 AggregateResponse (org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse)7 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)7 Region (org.apache.hadoop.hbase.regionserver.Region)6 Configuration (org.apache.hadoop.conf.Configuration)5 KeyValue (org.apache.hadoop.hbase.KeyValue)5 HashMap (java.util.HashMap)4 ScanType (org.apache.hadoop.hbase.regionserver.ScanType)4 StoreFileScanner (org.apache.hadoop.hbase.regionserver.StoreFileScanner)4 ByteString (com.google.protobuf.ByteString)3