Java Code Examples for org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange

The following examples show how to use org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: envelope   Source File: HBaseUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static Scan mergeRangeScans(List<Scan> rangeScans) {
  List<RowRange> ranges = Lists.newArrayList();
  
  for (Scan rangeScan : rangeScans) {
    byte[] startRow = rangeScan.getStartRow();
    byte[] stopRow = rangeScan.getStopRow();
    
    ranges.add(new RowRange(startRow, true, stopRow, false));
  }
  
  Scan mergedScan = new Scan();
  try {
    mergedScan.setFilter(new MultiRowRangeFilter(ranges));
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
  
  return mergedScan;
}
 
Example 2
Source Project: envelope   Source File: TestHBaseUtils.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMergePrefixScans() throws IOException {
  List<Scan> scans = Lists.newArrayList();
  
  byte[] startRow1 = Bytes.toBytes("hello");
  byte[] stopRow1 = Bytes.toBytes("hellp");
  Scan scan1 = new Scan(startRow1, stopRow1);
  scans.add(scan1);
  
  byte[] startRow2 = Bytes.toBytes("world");
  byte[] stopRow2 = Bytes.toBytes("worle");
  Scan scan2 = new Scan(startRow2, stopRow2);
  scans.add(scan2);
  
  Scan merged = HBaseUtils.mergeRangeScans(scans);
  
  assertEquals(MultiRowRangeFilter.class, merged.getFilter().getClass());
  MultiRowRangeFilter mergedFilter = (MultiRowRangeFilter)merged.getFilter();
  List<RowRange> ranges = mergedFilter.getRowRanges();
  assertEquals(2, ranges.size());
  assertTrue(ranges.get(0).getStartRow().equals(startRow1));
  assertTrue(ranges.get(0).getStopRow().equals(stopRow1));
  assertTrue(ranges.get(1).getStartRow().equals(startRow2));
  assertTrue(ranges.get(1).getStopRow().equals(stopRow2));
}
 
Example 3
Source Project: java-docs-samples   Source File: ReadData.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get the ranges to scan for the given time index.
 */
private List<RowRange> getRangesForTimeIndex(@Element Integer timeOffsetIndex, long maxInput) {
  List<RowRange> ranges = new ArrayList<>();

  int numRows = imageData.size();
  int numCols = imageData.get(0).size();
  int rowHeight = (int) (maxInput / numRows);
  int columnIndex = timeOffsetIndex % numCols;

  for (int i = 0; i < imageData.size(); i++) {
    // To generate shading, only scan each pixel with a probability based on it's weight.
    if (Math.random() <= imageData.get(i).get(columnIndex)) {
      // Get the indexes of the rowkeys for the interval.
      long startKeyI = maxInput - (i + 1) * rowHeight;
      long endKeyI = startKeyI + rowHeight;

      String startKey = keys[Math.toIntExact(startKeyI)];
      String endKey = keys[Math.toIntExact(endKeyI) - 1];
      ranges.add(
          new RowRange(
              Bytes.toBytes("" + startKey), true,
              Bytes.toBytes("" + endKey), true));
    }
  }
  return ranges;
}
 
Example 4
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testRanges() throws IOException {
  byte[] key1Start = new byte[] {-3};
  byte[] key1End  = new byte[] {-2};

  byte[] key2Start = new byte[] {5};
  byte[] key2End  = new byte[] {6};

  byte[] badKey = new byte[] {-10};

  MultiRowRangeFilter filter = new MultiRowRangeFilter(Arrays.asList(
    new MultiRowRangeFilter.RowRange(key1Start, true, key1End, false),
    new MultiRowRangeFilter.RowRange(key2Start, true, key2End, false)
      ));
  filter.filterRowKey(KeyValueUtil.createFirstOnRow(badKey));
  /*
   * FAILS -- includes BAD key!
   * Expected :SEEK_NEXT_USING_HINT
   * Actual   :INCLUDE
   * */
  assertEquals(Filter.ReturnCode.SEEK_NEXT_USING_HINT, filter.filterCell(null));
}
 
Example 5
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testOutOfOrderScannerNextException() throws Exception {
  MultiRowRangeFilter filter = new MultiRowRangeFilter(Arrays.asList(
          new MultiRowRangeFilter.RowRange(Bytes.toBytes("b"), true, Bytes.toBytes("c"), true),
          new MultiRowRangeFilter.RowRange(Bytes.toBytes("d"), true, Bytes.toBytes("e"), true)
  ));
  filter.filterRowKey(KeyValueUtil.createFirstOnRow(Bytes.toBytes("a")));
  assertEquals(Filter.ReturnCode.SEEK_NEXT_USING_HINT, filter.filterCell(null));
  filter.filterRowKey(KeyValueUtil.createFirstOnRow(Bytes.toBytes("b")));
  assertEquals(Filter.ReturnCode.INCLUDE, filter.filterCell(null));
  filter.filterRowKey(KeyValueUtil.createFirstOnRow(Bytes.toBytes("c")));
  assertEquals(Filter.ReturnCode.INCLUDE, filter.filterCell(null));
  filter.filterRowKey(KeyValueUtil.createFirstOnRow(Bytes.toBytes("d")));
  assertEquals(Filter.ReturnCode.INCLUDE, filter.filterCell(null));
  filter.filterRowKey(KeyValueUtil.createFirstOnRow(Bytes.toBytes("e")));
  assertEquals(Filter.ReturnCode.INCLUDE, filter.filterCell(null));
}
 
Example 6
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 7
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiRowRangeFilterWithoutRangeOverlap() 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(30), true, Bytes.toBytes(40), false));
  ranges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false));
  ranges.add(new RowRange(Bytes.toBytes(60), true, Bytes.toBytes(70), 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(20), ht);
  List<Cell> results2 = getScanResult(Bytes.toBytes(30), Bytes.toBytes(40), ht);
  List<Cell> results3 = getScanResult(Bytes.toBytes(60), Bytes.toBytes(70), ht);

  assertEquals(results1.size() + results2.size() + results3.size(), resultsSize);

  ht.close();
}
 
Example 8
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiRowRangeFilterWithEmptyStartRow() 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(""), true, Bytes.toBytes(10), 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(""), Bytes.toBytes(10), ht);
  List<Cell> results2 = getScanResult(Bytes.toBytes(30), Bytes.toBytes(40), ht);
  assertEquals(results1.size() + results2.size(), resultsSize);

  ht.close();
}
 
Example 9
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 10
Source Project: geowave   Source File: HBaseReader.java    License: Apache License 2.0 6 votes vote down vote up
protected Scan getMultiScanner(final FilterList filterList) {
  // Single scan w/ multiple ranges
  final Scan multiScanner = scanProvider.get();
  final List<ByteArrayRange> ranges = readerParams.getQueryRanges().getCompositeQueryRanges();

  final MultiRowRangeFilter filter = operations.getMultiRowRangeFilter(ranges);
  if (filter != null) {
    filterList.addFilter(filter);

    final List<RowRange> rowRanges = filter.getRowRanges();
    multiScanner.setStartRow(rowRanges.get(0).getStartRow());

    final RowRange stopRowRange = rowRanges.get(rowRanges.size() - 1);
    byte[] stopRowExclusive;
    if (stopRowRange.isStopRowInclusive()) {
      // because the end is always exclusive, to make an inclusive
      // stop row into exlusive all we need to do is add a traling 0
      stopRowExclusive = HBaseUtils.getInclusiveEndKey(stopRowRange.getStopRow());
    } else {
      stopRowExclusive = stopRowRange.getStopRow();
    }
    multiScanner.setStopRow(stopRowExclusive);
  }
  return multiScanner;
}
 
Example 11
Source Project: java-docs-samples   Source File: Reads.java    License: Apache License 2.0 5 votes vote down vote up
public static void readRowRanges(String projectId, String instanceId, String tableId) {
  // Initialize client that will be used to send requests. This client only needs to be created
  // once, and can be reused for multiple requests. After completing all of your requests, call
  // the "close" method on the client to safely clean up any remaining background resources.
  try (Connection connection = BigtableConfiguration.connect(projectId, instanceId)) {
    Table table = connection.getTable(TableName.valueOf(tableId));
    List<RowRange> ranges = new ArrayList<>();

    ranges.add(
        new RowRange(
            Bytes.toBytes("phone#4c410523#20190501"),
            true,
            Bytes.toBytes("phone#4c410523#20190601"),
            false));
    ranges.add(
        new RowRange(
            Bytes.toBytes("phone#5c10102#20190501"),
            true,
            Bytes.toBytes("phone#5c10102#20190601"),
            false));
    Filter filter = new MultiRowRangeFilter(ranges);
    Scan scan = new Scan().setFilter(filter);

    ResultScanner rows = table.getScanner(scan);

    for (Result row : rows) {
      printRow(row);
    }
  } catch (IOException e) {
    System.out.println(
        "Unable to initialize service client, as a network error occurred: \n" + e.toString());
  }
}
 
Example 12
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testRowKeyPrefixWithEmptyPrefix() throws IOException {
  byte[] prefix = {};
  byte[][] rowKeyPrefixes = new byte[1][];
  rowKeyPrefixes[0] = prefix;
  MultiRowRangeFilter filter = new MultiRowRangeFilter(rowKeyPrefixes);
  List<RowRange> actualRanges = filter.getRowRanges();
  List<RowRange> expectedRanges = new ArrayList<>();
  expectedRanges.add(
    new RowRange(HConstants.EMPTY_START_ROW, true, HConstants.EMPTY_END_ROW, false)
  );
  assertRangesEqual(expectedRanges, actualRanges);
}
 
Example 13
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testRowKeyPrefixWithLastIncrementablePrefix() throws IOException {
  byte[] prefix = {(byte) 0x12, (byte) 0x23, (byte) 0xFF, (byte) 0xFE};
  byte[][] rowKeyPrefixes = new byte[1][];
  rowKeyPrefixes[0] = prefix;
  MultiRowRangeFilter filter = new MultiRowRangeFilter(rowKeyPrefixes);
  List<RowRange> actualRanges = filter.getRowRanges();
  List<RowRange> expectedRanges = new ArrayList<>();
  final byte[] expectedStop = {(byte) 0x12, (byte) 0x23, (byte) 0xFF, (byte) 0xFF};
  expectedRanges.add(new RowRange(prefix, true, expectedStop , false));
  assertRangesEqual(expectedRanges, actualRanges);
}
 
Example 14
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testRowKeyPrefixWithoutLastIncrementablePrefix() throws IOException {
  byte[] prefix = {(byte) 0x12, (byte) 0x23, (byte) 0xFF, (byte) 0xFF};
  byte[][] rowKeyPrefixes = new byte[1][];
  rowKeyPrefixes[0] = prefix;
  MultiRowRangeFilter filter = new MultiRowRangeFilter(rowKeyPrefixes);
  List<RowRange> actualRanges = filter.getRowRanges();
  List<RowRange> expectedRanges = new ArrayList<>();
  final byte[] expectedStop = {(byte) 0x12, (byte) 0x24};
  expectedRanges.add(new RowRange(prefix, true, expectedStop , false));
  assertRangesEqual(expectedRanges, actualRanges);
}
 
Example 15
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testRowKeyPrefixWithMergablePrefix() throws IOException {
  byte[] prefix1 = {(byte) 0x12, (byte) 0x23, (byte) 0xFF, (byte) 0xFE};
  byte[] prefix2 = {(byte) 0x12, (byte) 0x23, (byte) 0xFF, (byte) 0xFF};
  byte[][] rowKeyPrefixes = new byte[2][];
  rowKeyPrefixes[0] = prefix1;
  rowKeyPrefixes[1] = prefix2;
  MultiRowRangeFilter filter = new MultiRowRangeFilter(rowKeyPrefixes);
  List<RowRange> actualRanges = filter.getRowRanges();
  List<RowRange> expectedRanges = new ArrayList<>();
  final byte[] expectedStop = {(byte) 0x12, (byte) 0x24};
  expectedRanges.add(new RowRange(prefix1, true, expectedStop , false));
  assertRangesEqual(expectedRanges, actualRanges);
}
 
Example 16
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 17
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testMergeAndSortWithEmptyStopRow() 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(""), 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(10), true, Bytes.toBytes(""), false));
  assertRangesEqual(expectedRanges, actualRanges);
}
 
Example 18
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 19
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 20
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testMergeAndSortWithoutOverlap() 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(30), true, Bytes.toBytes(40), false));
  ranges.add(new RowRange(Bytes.toBytes(60), true, Bytes.toBytes(70), 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(30), true, Bytes.toBytes(40), false));
  expectedRanges.add(new RowRange(Bytes.toBytes(60), true, Bytes.toBytes(70), false));
  assertRangesEqual(expectedRanges, actualRanges);
}
 
Example 21
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 22
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 23
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testMergeAndSortWithRowInclusive() throws IOException {
  List<RowRange> ranges = new ArrayList<>();
  ranges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), true));
  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(""), false));
  assertRangesEqual(expectedRanges, actualRanges);
}
 
Example 24
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
public void assertRangesEqual(List<RowRange> expected, List<RowRange> actual) {
  assertEquals(expected.size(), actual.size());
  for(int i = 0; i < expected.size(); i++) {
    Assert.assertTrue(Bytes.equals(expected.get(i).getStartRow(), actual.get(i).getStartRow()));
    Assert.assertTrue(expected.get(i).isStartRowInclusive() ==
        actual.get(i).isStartRowInclusive());
    Assert.assertTrue(Bytes.equals(expected.get(i).getStopRow(), actual.get(i).getStopRow()));
    Assert.assertTrue(expected.get(i).isStopRowInclusive() ==
        actual.get(i).isStopRowInclusive());
  }
}
 
Example 25
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
@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.readAllVersions();

  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();
}
 
Example 26
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 27
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiRowRangeFilterWithExclusive() throws IOException {
  tableName = TableName.valueOf(name.getMethodName());
  TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, 6000000);
  TEST_UTIL.createTable(tableName, family, Integer.MAX_VALUE);
  try (Table ht = TEST_UTIL.getConnection().getTableBuilder(tableName, null)
    .setReadRpcTimeout(600000).setOperationTimeout(6000000).build()) {
    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), false, Bytes.toBytes(40), false));
    ranges.add(new RowRange(Bytes.toBytes(65), true, Bytes.toBytes(75), 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(65), Bytes.toBytes(75), ht);

    assertEquals((results1.size() - 1) + results2.size(), resultsSize);
  }
}
 
Example 28
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
@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.readAllVersions();

  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();
}
 
Example 29
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiRowRangeWithFilterListOrOperator() 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> ranges1 = new ArrayList<>();
  ranges1.add(new RowRange(Bytes.toBytes(30), true, Bytes.toBytes(40), false));
  ranges1.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), 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_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(40), ht);
  List<Cell> results2 = getScanResult(Bytes.toBytes(60), Bytes.toBytes(70), ht);
  List<Cell> results3 = getScanResult(Bytes.toBytes(80), Bytes.toBytes(90), ht);

  assertEquals(results1.size() + results2.size() + results3.size(),resultsSize);

  ht.close();
}
 
Example 30
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testReverseMultiRowRangeFilterWithinTable() throws IOException {
  tableName = TableName.valueOf(name.getMethodName());
  Table ht = TEST_UTIL.createTable(tableName, family);
  generateRows(numRows, ht, family, qf, value);

  Scan scan = new Scan();
  scan.setReversed(true);
  List<RowRange> ranges = Arrays.asList(
      new RowRange(Bytes.toBytes(20), true, Bytes.toBytes(30), true),
      new RowRange(Bytes.toBytes(50), true, Bytes.toBytes(60), true)
  );
  MultiRowRangeFilter filter = new MultiRowRangeFilter(ranges);
  scan.setFilter(filter);

  List<Integer> expectedResults = new ArrayList<>();
  for (int i = 60; i >= 50; i--) {
    expectedResults.add(i);
  }
  for (int i = 30; i >= 20; i--) {
    expectedResults.add(i);
  }

  List<Cell> results = getResults(ht, scan);
  List<Integer> actualResults = new ArrayList<>();
  StringBuilder sb = new StringBuilder();
  for (Cell result : results) {
    int observedValue = Bytes.toInt(
        result.getRowArray(), result.getRowOffset(), result.getRowLength());
    actualResults.add(observedValue);
    if (sb.length() > 0) {
      sb.append(", ");
    }
    sb.append(observedValue);
  }
  assertEquals("Saw results: " + sb.toString(), 22, results.size());
}