use of org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange in project hbase by apache.
the class TestFilterListOrOperatorWithBlkCnt method testMultiRowRangeWithFilterListOrOperatorWithBlkCnt.
@Test
public void testMultiRowRangeWithFilterListOrOperatorWithBlkCnt() throws IOException {
tableName = TableName.valueOf(name.getMethodName());
Table ht = TEST_UTIL.createTable(tableName, family, Integer.MAX_VALUE);
generateRows(numRows, ht, family, qf, value);
Scan scan = new Scan();
scan.readAllVersions();
long blocksStart = getBlkAccessCount();
List<RowRange> ranges1 = new ArrayList<>();
ranges1.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(15), false));
ranges1.add(new RowRange(Bytes.toBytes(9980), true, Bytes.toBytes(9985), false));
MultiRowRangeFilter filter1 = new MultiRowRangeFilter(ranges1);
List<RowRange> ranges2 = new ArrayList<>();
ranges2.add(new RowRange(Bytes.toBytes(15), true, Bytes.toBytes(20), false));
ranges2.add(new RowRange(Bytes.toBytes(9985), true, Bytes.toBytes(9990), false));
MultiRowRangeFilter filter2 = new MultiRowRangeFilter(ranges2);
FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ONE);
filterList.addFilter(filter1);
filterList.addFilter(filter2);
scan.setFilter(filterList);
int resultsSize = getResultsSize(ht, scan);
LOG.info("found " + resultsSize + " results");
List<Cell> results1 = getScanResult(Bytes.toBytes(10), Bytes.toBytes(20), ht);
List<Cell> results2 = getScanResult(Bytes.toBytes(9980), Bytes.toBytes(9990), ht);
assertEquals(results1.size() + results2.size(), resultsSize);
long blocksEnd = getBlkAccessCount();
long diff = blocksEnd - blocksStart;
LOG.info("Diff in number of blocks " + diff);
/*
* Verify that we don't read all the blocks (8 in total).
*/
assertEquals(4, diff);
ht.close();
}
use of org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange in project hbase by apache.
the class TestMultiRowRangeFilter method testMergeAndSortWithEmptyStartRowAndStopRow.
@Test
public void testMergeAndSortWithEmptyStartRowAndStopRow() throws IOException {
List<RowRange> ranges = new ArrayList<>();
ranges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false));
ranges.add(new RowRange(Bytes.toBytes(""), true, Bytes.toBytes(""), false));
ranges.add(new RowRange(Bytes.toBytes(30), true, Bytes.toBytes(70), false));
List<RowRange> actualRanges = MultiRowRangeFilter.sortAndMerge(ranges);
List<RowRange> expectedRanges = new ArrayList<>();
expectedRanges.add(new RowRange(Bytes.toBytes(""), true, Bytes.toBytes(""), false));
assertRangesEqual(expectedRanges, actualRanges);
}
use of org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange in project hbase by apache.
the class TestMultiRowRangeFilter method testMergeAndSortWithStartRowInclusive.
@Test
public void testMergeAndSortWithStartRowInclusive() throws IOException {
List<RowRange> ranges = new ArrayList<>();
ranges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false));
ranges.add(new RowRange(Bytes.toBytes(20), true, Bytes.toBytes(""), false));
List<RowRange> actualRanges = MultiRowRangeFilter.sortAndMerge(ranges);
List<RowRange> expectedRanges = new ArrayList<>();
expectedRanges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(""), false));
assertRangesEqual(expectedRanges, actualRanges);
}
use of org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange in project hbase by apache.
the class TestMultiRowRangeFilter method testMergeAndSortWithEmptyStartRow.
@Test
public void testMergeAndSortWithEmptyStartRow() throws IOException {
List<RowRange> ranges = new ArrayList<>();
ranges.add(new RowRange(Bytes.toBytes(""), true, Bytes.toBytes(20), false));
ranges.add(new RowRange(Bytes.toBytes(15), true, Bytes.toBytes(40), false));
List<RowRange> actualRanges = MultiRowRangeFilter.sortAndMerge(ranges);
List<RowRange> expectedRanges = new ArrayList<>();
expectedRanges.add(new RowRange(Bytes.toBytes(""), true, Bytes.toBytes(40), false));
assertRangesEqual(expectedRanges, actualRanges);
}
use of org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange in project hbase by apache.
the class TestMultiRowRangeFilter method testReverseMultiRowRangeFilterIncludingMinAndMaxRow.
@Test
public void testReverseMultiRowRangeFilterIncludingMinAndMaxRow() throws IOException {
tableName = TableName.valueOf(name.getMethodName());
Table ht = TEST_UTIL.createTable(tableName, family);
for (String rowkey : Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h")) {
byte[] row = Bytes.toBytes(rowkey);
Put p = new Put(row);
p.addColumn(family, qf, value);
ht.put(p);
}
TEST_UTIL.flush();
Scan scan = new Scan();
scan.setReversed(true);
List<RowRange> ranges = Arrays.asList(new RowRange(Bytes.toBytes("a"), true, Bytes.toBytes("c"), true), new RowRange(Bytes.toBytes("f"), true, Bytes.toBytes("h"), true));
MultiRowRangeFilter filter = new MultiRowRangeFilter(ranges);
scan.setFilter(filter);
List<String> expected = Arrays.asList("h", "g", "f", "c", "b", "a");
List<String> actual = new ArrayList<>();
for (Cell cell : getResults(ht, scan)) {
actual.add(Bytes.toString(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()));
}
assertEquals(expected, actual);
}
Aggregations