Search in sources :

Example 6 with RowRange

use of org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange in project hbase by apache.

the class TestMultiRowRangeFilter method testMultiRowRangeFilterWithRangeOverlap.

@Test
public void testMultiRowRangeFilterWithRangeOverlap() 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.setMaxVersions();
    List<RowRange> ranges = new ArrayList<>();
    ranges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false));
    ranges.add(new RowRange(Bytes.toBytes(15), true, Bytes.toBytes(40), false));
    ranges.add(new RowRange(Bytes.toBytes(65), true, Bytes.toBytes(75), false));
    ranges.add(new RowRange(Bytes.toBytes(60), true, null, false));
    ranges.add(new RowRange(Bytes.toBytes(60), true, Bytes.toBytes(80), false));
    MultiRowRangeFilter filter = new MultiRowRangeFilter(ranges);
    scan.setFilter(filter);
    int resultsSize = getResultsSize(ht, scan);
    LOG.info("found " + resultsSize + " results");
    List<Cell> results1 = getScanResult(Bytes.toBytes(10), Bytes.toBytes(40), ht);
    List<Cell> results2 = getScanResult(Bytes.toBytes(60), Bytes.toBytes(""), ht);
    assertEquals(results1.size() + results2.size(), resultsSize);
    ht.close();
}
Also used : Table(org.apache.hadoop.hbase.client.Table) RowRange(org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange) ArrayList(java.util.ArrayList) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 7 with RowRange

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);
}
Also used : RowRange(org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with RowRange

use of org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange in project hbase by apache.

the class TestMultiRowRangeFilter method testMergeAndSortWithRowExclusive.

@Test
public void testMergeAndSortWithRowExclusive() 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), false, Bytes.toBytes(""), false));
    List<RowRange> actualRanges = MultiRowRangeFilter.sortAndMerge(ranges);
    List<RowRange> expectedRanges = new ArrayList<>();
    expectedRanges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false));
    expectedRanges.add(new RowRange(Bytes.toBytes(20), false, Bytes.toBytes(""), false));
    assertRangesEqual(expectedRanges, actualRanges);
}
Also used : RowRange(org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 9 with RowRange

use of org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange in project hbase by apache.

the class TestMultiRowRangeFilter method testMultiRowRangeWithInvalidRange.

@Test(expected = IllegalArgumentException.class)
public void testMultiRowRangeWithInvalidRange() throws IOException {
    List<RowRange> ranges = new ArrayList<>();
    ranges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false));
    // the start row larger than the stop row
    ranges.add(new RowRange(Bytes.toBytes(80), true, Bytes.toBytes(20), false));
    ranges.add(new RowRange(Bytes.toBytes(30), true, Bytes.toBytes(70), false));
    new MultiRowRangeFilter(ranges);
}
Also used : RowRange(org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 10 with RowRange

use of org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange in project hbase by apache.

the class TestMultiRowRangeFilter method testMultiRowRangeWithFilterListAndOperator.

@Test
public void testMultiRowRangeWithFilterListAndOperator() 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.setMaxVersions();
    List<RowRange> ranges1 = new ArrayList<>();
    ranges1.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false));
    ranges1.add(new RowRange(Bytes.toBytes(30), true, Bytes.toBytes(40), false));
    ranges1.add(new RowRange(Bytes.toBytes(60), true, Bytes.toBytes(70), false));
    MultiRowRangeFilter filter1 = new MultiRowRangeFilter(ranges1);
    List<RowRange> ranges2 = new ArrayList<>();
    ranges2.add(new RowRange(Bytes.toBytes(20), true, Bytes.toBytes(40), false));
    ranges2.add(new RowRange(Bytes.toBytes(80), true, Bytes.toBytes(90), false));
    MultiRowRangeFilter filter2 = new MultiRowRangeFilter(ranges2);
    FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);
    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(30), Bytes.toBytes(40), ht);
    assertEquals(results1.size(), resultsSize);
    ht.close();
}
Also used : Table(org.apache.hadoop.hbase.client.Table) RowRange(org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange) ArrayList(java.util.ArrayList) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)19 RowRange (org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange)19 Test (org.junit.Test)19 Cell (org.apache.hadoop.hbase.Cell)9 Scan (org.apache.hadoop.hbase.client.Scan)9 Table (org.apache.hadoop.hbase.client.Table)9