Search in sources :

Example 26 with InternalScanner

use of org.apache.hadoop.hbase.regionserver.InternalScanner in project hbase by apache.

the class TestColumnPrefixFilter method testColumnPrefixFilter.

@Test
public void testColumnPrefixFilter() throws IOException {
    String family = "Family";
    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
    htd.addFamily((new HColumnDescriptor(family)).setMaxVersions(3));
    HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
    HRegion region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.getDataTestDir(), TEST_UTIL.getConfiguration(), htd);
    try {
        List<String> rows = generateRandomWords(100, "row");
        List<String> columns = generateRandomWords(10000, "column");
        long maxTimestamp = 2;
        List<Cell> kvList = new ArrayList<>();
        Map<String, List<Cell>> prefixMap = new HashMap<>();
        prefixMap.put("p", new ArrayList<>());
        prefixMap.put("s", new ArrayList<>());
        String valueString = "ValueString";
        for (String row : rows) {
            Put p = new Put(Bytes.toBytes(row));
            p.setDurability(Durability.SKIP_WAL);
            for (String column : columns) {
                for (long timestamp = 1; timestamp <= maxTimestamp; timestamp++) {
                    KeyValue kv = KeyValueTestUtil.create(row, family, column, timestamp, valueString);
                    p.add(kv);
                    kvList.add(kv);
                    for (String s : prefixMap.keySet()) {
                        if (column.startsWith(s)) {
                            prefixMap.get(s).add(kv);
                        }
                    }
                }
            }
            region.put(p);
        }
        ColumnPrefixFilter filter;
        Scan scan = new Scan();
        scan.setMaxVersions();
        for (String s : prefixMap.keySet()) {
            filter = new ColumnPrefixFilter(Bytes.toBytes(s));
            scan.setFilter(filter);
            InternalScanner scanner = region.getScanner(scan);
            List<Cell> results = new ArrayList<>();
            while (scanner.next(results)) ;
            assertEquals(prefixMap.get(s).size(), results.size());
        }
    } finally {
        HBaseTestingUtility.closeRegionAndWAL(region);
    }
    HBaseTestingUtility.closeRegionAndWAL(region);
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) InternalScanner(org.apache.hadoop.hbase.regionserver.InternalScanner) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Put(org.apache.hadoop.hbase.client.Put) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) ArrayList(java.util.ArrayList) List(java.util.List) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 27 with InternalScanner

use of org.apache.hadoop.hbase.regionserver.InternalScanner in project hbase by apache.

the class TestColumnPrefixFilter method testColumnPrefixFilterWithFilterList.

@Test
public void testColumnPrefixFilterWithFilterList() throws IOException {
    String family = "Family";
    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
    htd.addFamily((new HColumnDescriptor(family)).setMaxVersions(3));
    HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
    HRegion region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.getDataTestDir(), TEST_UTIL.getConfiguration(), htd);
    try {
        List<String> rows = generateRandomWords(100, "row");
        List<String> columns = generateRandomWords(10000, "column");
        long maxTimestamp = 2;
        List<Cell> kvList = new ArrayList<>();
        Map<String, List<Cell>> prefixMap = new HashMap<>();
        prefixMap.put("p", new ArrayList<>());
        prefixMap.put("s", new ArrayList<>());
        String valueString = "ValueString";
        for (String row : rows) {
            Put p = new Put(Bytes.toBytes(row));
            p.setDurability(Durability.SKIP_WAL);
            for (String column : columns) {
                for (long timestamp = 1; timestamp <= maxTimestamp; timestamp++) {
                    KeyValue kv = KeyValueTestUtil.create(row, family, column, timestamp, valueString);
                    p.add(kv);
                    kvList.add(kv);
                    for (String s : prefixMap.keySet()) {
                        if (column.startsWith(s)) {
                            prefixMap.get(s).add(kv);
                        }
                    }
                }
            }
            region.put(p);
        }
        ColumnPrefixFilter filter;
        Scan scan = new Scan();
        scan.setMaxVersions();
        for (String s : prefixMap.keySet()) {
            filter = new ColumnPrefixFilter(Bytes.toBytes(s));
            //this is how this test differs from the one above
            FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);
            filterList.addFilter(filter);
            scan.setFilter(filterList);
            InternalScanner scanner = region.getScanner(scan);
            List<Cell> results = new ArrayList<>();
            while (scanner.next(results)) ;
            assertEquals(prefixMap.get(s).size(), results.size());
        }
    } finally {
        HBaseTestingUtility.closeRegionAndWAL(region);
    }
    HBaseTestingUtility.closeRegionAndWAL(region);
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) InternalScanner(org.apache.hadoop.hbase.regionserver.InternalScanner) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Put(org.apache.hadoop.hbase.client.Put) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) ArrayList(java.util.ArrayList) List(java.util.List) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 28 with InternalScanner

use of org.apache.hadoop.hbase.regionserver.InternalScanner in project hbase by apache.

the class TestDependentColumnFilter method verifyScan.

/**
   * This shouldn't be confused with TestFilter#verifyScan
   * as expectedKeys is not the per row total, but the scan total
   *
   * @param s
   * @param expectedRows
   * @param expectedCells
   * @throws IOException
   */
private void verifyScan(Scan s, long expectedRows, long expectedCells) throws IOException {
    InternalScanner scanner = this.region.getScanner(s);
    List<Cell> results = new ArrayList<>();
    int i = 0;
    int cells = 0;
    for (boolean done = true; done; i++) {
        done = scanner.next(results);
        Arrays.sort(results.toArray(new Cell[results.size()]), CellComparator.COMPARATOR);
        LOG.info("counter=" + i + ", " + results);
        if (results.isEmpty())
            break;
        cells += results.size();
        assertTrue("Scanned too many rows! Only expected " + expectedRows + " total but already scanned " + (i + 1), expectedRows > i);
        assertTrue("Expected " + expectedCells + " cells total but " + "already scanned " + cells, expectedCells >= cells);
        results.clear();
    }
    assertEquals("Expected " + expectedRows + " rows but scanned " + i + " rows", expectedRows, i);
    assertEquals("Expected " + expectedCells + " cells but scanned " + cells + " cells", expectedCells, cells);
}
Also used : InternalScanner(org.apache.hadoop.hbase.regionserver.InternalScanner) ArrayList(java.util.ArrayList) Cell(org.apache.hadoop.hbase.Cell)

Example 29 with InternalScanner

use of org.apache.hadoop.hbase.regionserver.InternalScanner in project hbase by apache.

the class TestFilter method testWhileMatchFilterWithFilterRowWithReverseScan.

@Test
public void testWhileMatchFilterWithFilterRowWithReverseScan() throws Exception {
    final int pageSize = 4;
    Scan s = new Scan();
    s.setReversed(true);
    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) {
            Assert.assertTrue("The WhileMatchFilter should now filter all remaining", filter.filterAllRemaining());
        }
        if (!isMoreResults) {
            break;
        }
    }
    scanner.close();
    Assert.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 30 with InternalScanner

use of org.apache.hadoop.hbase.regionserver.InternalScanner in project hbase by apache.

the class TestFilter method verifyScan.

private void verifyScan(Scan s, long expectedRows, long expectedKeys) throws IOException {
    InternalScanner scanner = this.region.getScanner(s);
    List<Cell> results = new ArrayList<>();
    int i = 0;
    for (boolean done = true; done; i++) {
        done = scanner.next(results);
        Arrays.sort(results.toArray(new Cell[results.size()]), CellComparator.COMPARATOR);
        LOG.info("counter=" + i + ", " + results);
        if (results.isEmpty())
            break;
        assertTrue("Scanned too many rows! Only expected " + expectedRows + " total but already scanned " + (i + 1), expectedRows > i);
        assertEquals("Expected " + expectedKeys + " keys per row but " + "returned " + results.size(), expectedKeys, results.size());
        results.clear();
    }
    assertEquals("Expected " + expectedRows + " rows but scanned " + i + " rows", expectedRows, i);
}
Also used : InternalScanner(org.apache.hadoop.hbase.regionserver.InternalScanner) ArrayList(java.util.ArrayList) Cell(org.apache.hadoop.hbase.Cell)

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