Java Code Examples for org.apache.hadoop.hbase.client.Scan#readAllVersions()

The following examples show how to use org.apache.hadoop.hbase.client.Scan#readAllVersions() . 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 File: TestKeepDeletes.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * The ExplicitColumnTracker does not support "raw" scanning.
 */
@Test
public void testRawScanWithColumns() throws Exception {
  HTableDescriptor htd = hbu.createTableDescriptor(TableName.valueOf(name.getMethodName()), 0, 3,
      HConstants.FOREVER, KeepDeletedCells.TRUE);
  Region region = hbu.createLocalHRegion(htd, null, null);

  Scan s = new Scan();
  s.setRaw(true);
  s.readAllVersions();
  s.addColumn(c0, c0);

  try {
    region.getScanner(s);
    fail("raw scanner with columns should have failed");
  } catch (org.apache.hadoop.hbase.DoNotRetryIOException dnre) {
    // ok!
  }

  HBaseTestingUtility.closeRegionAndWAL(region);
}
 
Example 2
Source File: TestPartialResultsFromClientSide.java    From hbase with Apache License 2.0 6 votes vote down vote up
public void testExpectedValuesOfPartialResults(boolean reversed) throws Exception {
  Scan partialScan = new Scan();
  partialScan.readAllVersions();
  // Max result size of 1 ensures that each RPC request will return a single cell. The scanner
  // will need to reconstruct the results into a complete result before returning to the caller
  partialScan.setMaxResultSize(1);
  partialScan.setReversed(reversed);
  ResultScanner partialScanner = TABLE.getScanner(partialScan);

  final int startRow = reversed ? ROWS.length - 1 : 0;
  final int endRow = reversed ? -1 : ROWS.length;
  final int loopDelta = reversed ? -1 : 1;
  String message;

  for (int row = startRow; row != endRow; row = row + loopDelta) {
    message = "Ensuring the expected keyValues are present for row " + row;
    List<Cell> expectedKeyValues = createKeyValuesForRow(ROWS[row], FAMILIES, QUALIFIERS, VALUE);
    Result result = partialScanner.next();
    assertFalse(result.mayHaveMoreCellsInRow());
    verifyResult(result, expectedKeyValues, message);
  }

  partialScanner.close();
}
 
Example 3
Source File: TestMultiRowRangeFilter.java    From hbase with Apache License 2.0 6 votes vote down vote up
private List<Cell> getScanResult(byte[] startRow, byte[] stopRow, Table ht) throws IOException {
  Scan scan = new Scan();
  scan.readAllVersions();
  if(!Bytes.toString(startRow).isEmpty()) {
    scan.withStartRow(startRow);
  }
  if(!Bytes.toString(stopRow).isEmpty()) {
    scan.withStopRow(stopRow);
  }
  ResultScanner scanner = ht.getScanner(scan);
  List<Cell> kvList = new ArrayList<>();
  Result r;
  while ((r = scanner.next()) != null) {
    for (Cell kv : r.listCells()) {
      kvList.add(kv);
    }
  }
  scanner.close();
  return kvList;
}
 
Example 4
Source File: TestFilterListOrOperatorWithBlkCnt.java    From hbase with Apache License 2.0 6 votes vote down vote up
private List<Cell> getScanResult(byte[] startRow, byte[] stopRow, Table ht) throws IOException {
  Scan scan = new Scan();
  scan.readAllVersions();
  if(!Bytes.toString(startRow).isEmpty()) {
    scan.withStartRow(startRow);
  }
  if(!Bytes.toString(stopRow).isEmpty()) {
    scan.withStopRow(stopRow);
  }
  ResultScanner scanner = ht.getScanner(scan);
  List<Cell> kvList = new ArrayList<>();
  Result r;
  while ((r = scanner.next()) != null) {
    for (Cell kv : r.listCells()) {
      kvList.add(kv);
    }
  }
  return kvList;
}
 
Example 5
Source File: TestMultiRowRangeFilter.java    From hbase with 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 6
Source File: TestMultiRowRangeFilter.java    From hbase with 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 7
Source File: TestMultiRowRangeFilter.java    From hbase with 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 8
Source File: StatisticsUtil.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public static void setScanAttributes(Scan scan, Map<String, Object> statsProps) {
    scan.setCacheBlocks(false);
    scan.readAllVersions();
    scan.setAttribute(ANALYZE_TABLE, TRUE_BYTES);
    if (statsProps != null) {
        Object gp_width = statsProps.get(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB);
        if (gp_width != null) {
            scan.setAttribute(BaseScannerRegionObserver.GUIDEPOST_WIDTH_BYTES, PLong.INSTANCE.toBytes(gp_width));
        }
        Object gp_per_region = statsProps.get(QueryServices.STATS_GUIDEPOST_PER_REGION_ATTRIB);
        if (gp_per_region != null) {
            scan.setAttribute(BaseScannerRegionObserver.GUIDEPOST_PER_REGION, PInteger.INSTANCE.toBytes(gp_per_region));
        }
    }
}
 
Example 9
Source File: TestMultiRowRangeFilter.java    From hbase with 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 10
Source File: TestMultiRowRangeFilter.java    From hbase with 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 11
Source File: TestMultiRowRangeFilter.java    From hbase with 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 12
Source File: TestMultiRowRangeFilter.java    From hbase with 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 13
Source File: TestMultiRowRangeFilter.java    From hbase with 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 14
Source File: TestFilterListOrOperatorWithBlkCnt.java    From hbase with Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example 15
Source File: TestMultipleColumnPrefixFilter.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testMultipleColumnPrefixFilter() throws IOException {
  String family = "Family";
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName()));
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder
      .newBuilder(Bytes.toBytes(family))
      .setMaxVersions(3)
      .build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  TableDescriptor tableDescriptor = tableDescriptorBuilder.build();
  // HRegionInfo info = new HRegionInfo(htd, null, null, false);
  RegionInfo info = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName()).build();
  HRegion region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.
      getDataTestDir(), TEST_UTIL.getConfiguration(), tableDescriptor);

  List<String> rows = generateRandomWords(100, "row");
  List<String> columns = generateRandomWords(10000, "column");
  long maxTimestamp = 2;

  List<Cell> kvList = new ArrayList<>();

  Map<String, List<Cell>> prefixMap = new HashMap<>();

  prefixMap.put("p", new ArrayList<>());
  prefixMap.put("q", new ArrayList<>());
  prefixMap.put("s", new ArrayList<>());

  String valueString = "ValueString";

  for (String row: rows) {
    Put p = new Put(Bytes.toBytes(row));
    p.setDurability(Durability.SKIP_WAL);
    for (String column: columns) {
      for (long timestamp = 1; timestamp <= maxTimestamp; timestamp++) {
        KeyValue kv = KeyValueTestUtil.create(row, family, column, timestamp,
            valueString);
        p.add(kv);
        kvList.add(kv);
        for (String s: prefixMap.keySet()) {
          if (column.startsWith(s)) {
            prefixMap.get(s).add(kv);
          }
        }
      }
    }
    region.put(p);
  }

  MultipleColumnPrefixFilter filter;
  Scan scan = new Scan();
  scan.readAllVersions();
  byte [][] filter_prefix = new byte [2][];
  filter_prefix[0] = new byte [] {'p'};
  filter_prefix[1] = new byte [] {'q'};

  filter = new MultipleColumnPrefixFilter(filter_prefix);
  scan.setFilter(filter);
  List<Cell> results = new ArrayList<>();
  InternalScanner scanner = region.getScanner(scan);
  while (scanner.next(results))
    ;
  assertEquals(prefixMap.get("p").size() + prefixMap.get("q").size(), results.size());

  HBaseTestingUtility.closeRegionAndWAL(region);
}
 
Example 16
Source File: TestMultipleColumnPrefixFilter.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testMultipleColumnPrefixFilterWithManyFamilies() throws IOException {
  String family1 = "Family1";
  String family2 = "Family2";
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName()));
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder
      .newBuilder(Bytes.toBytes(family1))
      .setMaxVersions(3)
      .build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  columnFamilyDescriptor = ColumnFamilyDescriptorBuilder
    .newBuilder(Bytes.toBytes(family2))
    .setMaxVersions(3)
    .build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  TableDescriptor tableDescriptor = tableDescriptorBuilder.build();
  RegionInfo info = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName()).build();
  HRegion region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.
    getDataTestDir(), TEST_UTIL.getConfiguration(), tableDescriptor);

  List<String> rows = generateRandomWords(100, "row");
  List<String> columns = generateRandomWords(10000, "column");
  long maxTimestamp = 3;

  List<Cell> kvList = new ArrayList<>();

  Map<String, List<Cell>> prefixMap = new HashMap<>();

  prefixMap.put("p", new ArrayList<>());
  prefixMap.put("q", new ArrayList<>());
  prefixMap.put("s", new ArrayList<>());

  String valueString = "ValueString";

  for (String row: rows) {
    Put p = new Put(Bytes.toBytes(row));
    p.setDurability(Durability.SKIP_WAL);
    for (String column: columns) {
      for (long timestamp = 1; timestamp <= maxTimestamp; timestamp++) {
        double rand = Math.random();
        Cell kv;
        if (rand < 0.5) {
          kv = KeyValueTestUtil.create(row, family1, column, timestamp, valueString);
        } else {
          kv = KeyValueTestUtil.create(row, family2, column, timestamp, valueString);
        }
        p.add(kv);
        kvList.add(kv);
        for (String s: prefixMap.keySet()) {
          if (column.startsWith(s)) {
            prefixMap.get(s).add(kv);
          }
        }
      }
    }
    region.put(p);
  }

  MultipleColumnPrefixFilter filter;
  Scan scan = new Scan();
  scan.readAllVersions();
  byte [][] filter_prefix = new byte [2][];
  filter_prefix[0] = new byte [] {'p'};
  filter_prefix[1] = new byte [] {'q'};

  filter = new MultipleColumnPrefixFilter(filter_prefix);
  scan.setFilter(filter);
  List<Cell> results = new ArrayList<>();
  InternalScanner scanner = region.getScanner(scan);
  while (scanner.next(results))
    ;
  assertEquals(prefixMap.get("p").size() + prefixMap.get("q").size(), results.size());

  HBaseTestingUtility.closeRegionAndWAL(region);
}
 
Example 17
Source File: TestMultipleColumnPrefixFilter.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testMultipleColumnPrefixFilterWithColumnPrefixFilter() throws IOException {
  String family = "Family";
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName()));
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(family)).build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  TableDescriptor tableDescriptor = tableDescriptorBuilder.build();
  RegionInfo info = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName()).build();
  HRegion region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.
    getDataTestDir(), TEST_UTIL.getConfiguration(), tableDescriptor);

  List<String> rows = generateRandomWords(100, "row");
  List<String> columns = generateRandomWords(10000, "column");
  long maxTimestamp = 2;

  String valueString = "ValueString";

  for (String row: rows) {
    Put p = new Put(Bytes.toBytes(row));
    p.setDurability(Durability.SKIP_WAL);
    for (String column: columns) {
      for (long timestamp = 1; timestamp <= maxTimestamp; timestamp++) {
        KeyValue kv = KeyValueTestUtil.create(row, family, column, timestamp,
            valueString);
        p.add(kv);
      }
    }
    region.put(p);
  }

  MultipleColumnPrefixFilter multiplePrefixFilter;
  Scan scan1 = new Scan();
  scan1.readAllVersions();
  byte [][] filter_prefix = new byte [1][];
  filter_prefix[0] = new byte [] {'p'};

  multiplePrefixFilter = new MultipleColumnPrefixFilter(filter_prefix);
  scan1.setFilter(multiplePrefixFilter);
  List<Cell> results1 = new ArrayList<>();
  InternalScanner scanner1 = region.getScanner(scan1);
  while (scanner1.next(results1))
    ;

  ColumnPrefixFilter singlePrefixFilter;
  Scan scan2 = new Scan();
  scan2.readAllVersions();
  singlePrefixFilter = new ColumnPrefixFilter(Bytes.toBytes("p"));

  scan2.setFilter(singlePrefixFilter);
  List<Cell> results2 = new ArrayList<>();
  InternalScanner scanner2 = region.getScanner(scan1);
  while (scanner2.next(results2))
    ;

  assertEquals(results1.size(), results2.size());

  HBaseTestingUtility.closeRegionAndWAL(region);
}
 
Example 18
Source File: TestStoreScanner.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testScanTimeRange() throws IOException {
  String r1 = "R1";
  // returns only 1 of these 2 even though same timestamp
  KeyValue [] kvs = new KeyValue[] {
      create(r1, CF_STR, "a", 1, KeyValue.Type.Put, "dont-care"),
      create(r1, CF_STR, "a", 2, KeyValue.Type.Put, "dont-care"),
      create(r1, CF_STR, "a", 3, KeyValue.Type.Put, "dont-care"),
      create(r1, CF_STR, "a", 4, KeyValue.Type.Put, "dont-care"),
      create(r1, CF_STR, "a", 5, KeyValue.Type.Put, "dont-care"),
  };
  List<KeyValueScanner> scanners = Arrays.<KeyValueScanner>asList(
    new KeyValueScanner[] {new KeyValueScanFixture(CellComparator.getInstance(), kvs)});
  Scan scanSpec = new Scan().withStartRow(Bytes.toBytes(r1));
  scanSpec.setTimeRange(0, 6);
  scanSpec.readAllVersions();
  List<Cell> results = null;
  try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, getCols("a"), scanners)) {
    results = new ArrayList<>();
    assertEquals(true, scan.next(results));
    assertEquals(5, results.size());
    assertEquals(kvs[kvs.length - 1], results.get(0));
  }
  // Scan limited TimeRange
  scanSpec = new Scan().withStartRow(Bytes.toBytes(r1));
  scanSpec.setTimeRange(1, 3);
  scanSpec.readAllVersions();
  try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, getCols("a"), scanners)) {
    results = new ArrayList<>();
    assertEquals(true, scan.next(results));
    assertEquals(2, results.size());
  }
  // Another range.
  scanSpec = new Scan().withStartRow(Bytes.toBytes(r1));
  scanSpec.setTimeRange(5, 10);
  scanSpec.readAllVersions();
  try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, getCols("a"), scanners)) {
    results = new ArrayList<>();
    assertEquals(true, scan.next(results));
    assertEquals(1, results.size());
  }
  // See how TimeRange and Versions interact.
  // Another range.
  scanSpec = new Scan().withStartRow(Bytes.toBytes(r1));
  scanSpec.setTimeRange(0, 10);
  scanSpec.readVersions(3);
  try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, getCols("a"), scanners)) {
    results = new ArrayList<>();
    assertEquals(true, scan.next(results));
    assertEquals(3, results.size());
  }
}
 
Example 19
Source File: TestKeepDeletes.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * basic verification of existing behavior
 */
@Test
public void testWithoutKeepingDeletes() throws Exception {
  // KEEP_DELETED_CELLS is NOT enabled
  HTableDescriptor htd = hbu.createTableDescriptor(TableName.valueOf(name.getMethodName()), 0, 3,
      HConstants.FOREVER, KeepDeletedCells.FALSE);
  HRegion region = hbu.createLocalHRegion(htd, null, null);

  long ts = EnvironmentEdgeManager.currentTime();
  Put p = new Put(T1, ts);
  p.addColumn(c0, c0, T1);
  region.put(p);

  Get gOne = new Get(T1);
  gOne.readAllVersions();
  gOne.setTimeRange(0L, ts + 1);
  Result rOne = region.get(gOne);
  assertFalse(rOne.isEmpty());


  Delete d = new Delete(T1, ts+2);
  d.addColumn(c0, c0, ts);
  region.delete(d);

  // "past" get does not see rows behind delete marker
  Get g = new Get(T1);
  g.readAllVersions();
  g.setTimeRange(0L, ts+1);
  Result r = region.get(g);
  assertTrue(r.isEmpty());

  // "past" scan does not see rows behind delete marker
  Scan s = new Scan();
  s.readAllVersions();
  s.setTimeRange(0L, ts+1);
  InternalScanner scanner = region.getScanner(s);
  List<Cell> kvs = new ArrayList<>();
  while (scanner.next(kvs)) {
    continue;
  }
  assertTrue(kvs.isEmpty());

  // flushing and minor compaction keep delete markers
  region.flush(true);
  region.compact(false);
  assertEquals(1, countDeleteMarkers(region));
  region.compact(true);
  // major compaction deleted it
  assertEquals(0, countDeleteMarkers(region));

  HBaseTestingUtility.closeRegionAndWAL(region);
}