Search in sources :

Example 21 with RowRange

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

the class TestMultiRowRangeFilter method testReverseMultiRowRangeFilterIncludingMinRow.

@Test
public void testReverseMultiRowRangeFilterIncludingMinRow() 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("g"), true));
    MultiRowRangeFilter filter = new MultiRowRangeFilter(ranges);
    scan.setFilter(filter);
    List<String> expected = Arrays.asList("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);
}
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) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 22 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 23 with RowRange

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

the class TestMultiRowRangeFilter method testMultiRowRangeFilterWithInclusive.

@Test
public void testMultiRowRangeFilterWithInclusive() 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();
    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(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 24 with RowRange

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

the class TestMultiRowRangeFilter method testMultiRowRangeFilterWithEmptyStopRow.

@Test
public void testMultiRowRangeFilterWithEmptyStopRow() 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();
    List<RowRange> ranges = new ArrayList<>();
    ranges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(""), false));
    ranges.add(new RowRange(Bytes.toBytes(30), true, Bytes.toBytes(40), false));
    MultiRowRangeFilter filter = new MultiRowRangeFilter(ranges);
    scan.setFilter(filter);
    int resultsSize = getResultsSize(ht, scan);
    List<Cell> results1 = getScanResult(Bytes.toBytes(10), Bytes.toBytes(""), 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)

Example 25 with RowRange

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

the class TestMultiRowRangeFilter method testMergeAndSortWithOverlap.

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

Aggregations

RowRange (org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange)29 ArrayList (java.util.ArrayList)28 Test (org.junit.Test)27 Cell (org.apache.hadoop.hbase.Cell)13 Scan (org.apache.hadoop.hbase.client.Scan)13 Table (org.apache.hadoop.hbase.client.Table)13 Put (org.apache.hadoop.hbase.client.Put)3 DirectedType (uk.gov.gchq.gaffer.data.element.id.DirectedType)2 SeedMatching (uk.gov.gchq.gaffer.operation.SeedMatching)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Pair (uk.gov.gchq.gaffer.commonutil.pair.Pair)1 EdgeId (uk.gov.gchq.gaffer.data.element.id.EdgeId)1 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)1 SeededGraphFilters (uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters)1 IncludeIncomingOutgoingType (uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters.IncludeIncomingOutgoingType)1