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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations