Java 类org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange 实例源码

项目:ditb    文件:TestMultiRowRangeFilter.java   
@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(badKey, 0, 1);
  assertEquals(Filter.ReturnCode.SEEK_NEXT_USING_HINT, filter.filterKeyValue(null));
}
项目:ditb    文件:TestMultiRowRangeFilter.java   
@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(Bytes.toBytes("a"), 0, 1);
  assertEquals(Filter.ReturnCode.SEEK_NEXT_USING_HINT, filter.filterKeyValue(null));
  filter.filterRowKey(Bytes.toBytes("b"), 0, 1);
  assertEquals(Filter.ReturnCode.INCLUDE, filter.filterKeyValue(null));
  filter.filterRowKey(Bytes.toBytes("c"), 0, 1);
  assertEquals(Filter.ReturnCode.INCLUDE, filter.filterKeyValue(null));
  filter.filterRowKey(Bytes.toBytes("d"), 0, 1);
  assertEquals(Filter.ReturnCode.INCLUDE, filter.filterKeyValue(null));
  filter.filterRowKey(Bytes.toBytes("e"), 0, 1);
  assertEquals(Filter.ReturnCode.INCLUDE, filter.filterKeyValue(null));
}
项目:ditb    文件:TestMultiRowRangeFilter.java   
@Test
public void testMergeAndSortWithOverlap() throws IOException {
  List<RowRange> ranges = new ArrayList<RowRange>();
  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<RowRange>();
  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);
}
项目:ditb    文件:TestMultiRowRangeFilter.java   
@Test
public void testMultiRowRangeFilterWithoutRangeOverlap() throws IOException {
  tableName = Bytes.toBytes("testMultiRowRangeFilterWithoutRangeOverlap");
  HTable 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<RowRange>();
  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();
}
项目:ditb    文件:TestMultiRowRangeFilter.java   
@Test
public void testMultiRowRangeFilterWithEmptyStartRow() throws IOException {
  tableName = Bytes.toBytes("testMultiRowRangeFilterWithEmptyStartRow");
  HTable 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<RowRange>();
  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();
}
项目:ditb    文件:TestMultiRowRangeFilter.java   
@Test
public void testMultiRowRangeFilterWithEmptyStopRow() throws IOException {
  tableName = Bytes.toBytes("testMultiRowRangeFilterWithEmptyStopRow");
  HTable 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<RowRange>();
  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();
}
项目:ditb    文件:TestMultiRowRangeFilter.java   
@Test
public void testMultiRowRangeFilterWithExclusive() throws IOException {
  tableName = Bytes.toBytes("testMultiRowRangeFilterWithExclusive");
  HTable 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<RowRange>();
  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);

  ht.close();
}
项目:envelope    文件:HBaseUtils.java   
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;
}
项目:envelope    文件:TestHBaseUtils.java   
@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));
}
项目:hbase    文件:TestMultiRowRangeFilter.java   
@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));
}
项目:hbase    文件:TestMultiRowRangeFilter.java   
@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));
}
项目:hbase    文件:TestMultiRowRangeFilter.java   
@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);
}
项目:hbase    文件:TestMultiRowRangeFilter.java   
@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.setMaxVersions();

  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();
}
项目:hbase    文件:TestMultiRowRangeFilter.java   
@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.setMaxVersions();

  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();
}
项目:hbase    文件:TestMultiRowRangeFilter.java   
@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.setMaxVersions();

  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();
}
项目:ditb    文件:TestMultiRowRangeFilter.java   
@Test
public void testMergeAndSortWithEmptyStartRow() throws IOException {
  List<RowRange> ranges = new ArrayList<RowRange>();
  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<RowRange>();
  expectedRanges.add(new RowRange(Bytes.toBytes(""), true, Bytes.toBytes(40), false));
  assertRangesEqual(expectedRanges, actualRanges);
}
项目:ditb    文件:TestMultiRowRangeFilter.java   
@Test
public void testMergeAndSortWithEmptyStopRow() throws IOException {
  List<RowRange> ranges = new ArrayList<RowRange>();
  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<RowRange>();
  expectedRanges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(""), false));
  assertRangesEqual(expectedRanges, actualRanges);
}
项目:ditb    文件:TestMultiRowRangeFilter.java   
@Test
public void testMergeAndSortWithEmptyStartRowAndStopRow() throws IOException {
  List<RowRange> ranges = new ArrayList<RowRange>();
  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<RowRange>();
  expectedRanges.add(new RowRange(Bytes.toBytes(""), true, Bytes.toBytes(""), false));
  assertRangesEqual(expectedRanges, actualRanges);
}
项目:ditb    文件:TestMultiRowRangeFilter.java   
@Test(expected=IllegalArgumentException.class)
public void testMultiRowRangeWithInvalidRange() throws IOException {
  List<RowRange> ranges = new ArrayList<RowRange>();
  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);
}
项目:ditb    文件:TestMultiRowRangeFilter.java   
@Test
public void testMergeAndSortWithoutOverlap() throws IOException {
  List<RowRange> ranges = new ArrayList<RowRange>();
  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<RowRange>();
  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);
}
项目:ditb    文件:TestMultiRowRangeFilter.java   
@Test
public void testMergeAndSortWithStartRowInclusive() throws IOException {
  List<RowRange> ranges = new ArrayList<RowRange>();
  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<RowRange>();
  expectedRanges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(""), false));
  assertRangesEqual(expectedRanges, actualRanges);
}
项目:ditb    文件:TestMultiRowRangeFilter.java   
@Test
public void testMergeAndSortWithRowExclusive() throws IOException {
  List<RowRange> ranges = new ArrayList<RowRange>();
  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<RowRange>();
  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);
}
项目:ditb    文件:TestMultiRowRangeFilter.java   
@Test
public void testMergeAndSortWithRowInclusive() throws IOException {
  List<RowRange> ranges = new ArrayList<RowRange>();
  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<RowRange>();
  expectedRanges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(""), false));
  assertRangesEqual(expectedRanges, actualRanges);
}
项目:ditb    文件:TestMultiRowRangeFilter.java   
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());
  }
}
项目:ditb    文件:TestMultiRowRangeFilter.java   
@Test
public void testMultiRowRangeFilterWithRangeOverlap() throws IOException {
  tableName = Bytes.toBytes("testMultiRowRangeFilterWithRangeOverlap");
  HTable 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<RowRange>();
  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();
}
项目:ditb    文件:TestMultiRowRangeFilter.java   
@Test
public void testMultiRowRangeFilterWithInclusive() throws IOException {
  tableName = Bytes.toBytes("testMultiRowRangeFilterWithInclusive");
  HTable 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<RowRange>();
  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();
}
项目:ditb    文件:TestMultiRowRangeFilter.java   
@Test
public void testMultiRowRangeWithFilterListAndOperator() throws IOException {
  tableName = Bytes.toBytes("TestMultiRowRangeFilterWithFilterListAndOperator");
  HTable 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<RowRange>();
  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<RowRange>();
  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();
}
项目:ditb    文件:TestMultiRowRangeFilter.java   
@Test
public void testMultiRowRangeWithFilterListOrOperator() throws IOException {
  tableName = Bytes.toBytes("TestMultiRowRangeFilterWithFilterListOrOperator");
  HTable 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<RowRange>();
  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<RowRange>();
  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();
}
项目:ditb    文件:TestFilterSerialization.java   
@Test
public void testMultiRowRangeFilter() throws Exception {
  List<RowRange> ranges = new ArrayList<RowRange>();
  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 multiRowRangeFilter =
    new MultiRowRangeFilter(ranges);
  assertTrue(multiRowRangeFilter.areSerializedFieldsEqual(
    ProtobufUtil.toFilter(ProtobufUtil.toFilter(multiRowRangeFilter))));
}
项目:hbase    文件:TestMultiRowRangeFilter.java   
@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);
}
项目:hbase    文件:TestMultiRowRangeFilter.java   
@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);
}
项目:hbase    文件:TestMultiRowRangeFilter.java   
@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);
}
项目:hbase    文件:TestMultiRowRangeFilter.java   
@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);
}
项目:hbase    文件:TestMultiRowRangeFilter.java   
@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);
}
项目:hbase    文件:TestMultiRowRangeFilter.java   
@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);
}
项目:hbase    文件:TestMultiRowRangeFilter.java   
@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);
}
项目:hbase    文件:TestMultiRowRangeFilter.java   
@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);
}
项目:hbase    文件:TestMultiRowRangeFilter.java   
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());
  }
}
项目:hbase    文件:TestMultiRowRangeFilter.java   
@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();
}
项目:hbase    文件:TestMultiRowRangeFilter.java   
@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.setMaxVersions();

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