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

The following examples show how to use org.apache.hadoop.hbase.client.Scan#setReversed() . 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: hgraphdb   File: VertexIndexModel.java    License: Apache License 2.0 6 votes vote down vote up
private Scan getVertexIndexScanWithLimit(String label, boolean isUnique, String key, Object from, int limit, boolean reversed) {
    byte[] prefix = serializeForRead(label, isUnique, key, null);
    byte[] startRow = from != null
            ? serializeForRead(label, isUnique, key, from)
            : prefix;
    byte[] stopRow = HConstants.EMPTY_END_ROW;
    if (graph.configuration().getInstanceType() == HBaseGraphConfiguration.InstanceType.BIGTABLE) {
        if (reversed) {
            throw new UnsupportedOperationException("Reverse scans not supported by Bigtable");
        } else {
            // PrefixFilter in Bigtable does not automatically stop
            // See https://github.com/GoogleCloudPlatform/cloud-bigtable-client/issues/1087
            stopRow = HBaseGraphUtils.incrementBytes(prefix);
        }
    }
    if (reversed) startRow = HBaseGraphUtils.incrementBytes(startRow);
    Scan scan = new Scan(startRow, stopRow);
    FilterList filterList = new FilterList();
    filterList.addFilter(new PrefixFilter(prefix));
    filterList.addFilter(new PageFilter(limit));
    scan.setFilter(filterList);
    scan.setReversed(reversed);
    return scan;
}
 
Example 2
Source Project: hbase   File: MetaTableAccessor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @return Get closest metatable region row to passed <code>row</code>
 */
@NonNull
private static RegionInfo getClosestRegionInfo(Connection connection,
  @NonNull final TableName tableName, @NonNull final byte[] row) throws IOException {
  byte[] searchRow = RegionInfo.createRegionName(tableName, row, HConstants.NINES, false);
  Scan scan = getMetaScan(connection, 1);
  scan.setReversed(true);
  scan.withStartRow(searchRow);
  try (ResultScanner resultScanner = getMetaHTable(connection).getScanner(scan)) {
    Result result = resultScanner.next();
    if (result == null) {
      throw new TableNotFoundException("Cannot find row in META " + " for table: " + tableName +
        ", row=" + Bytes.toStringBinary(row));
    }
    RegionInfo regionInfo = CatalogFamilyFormat.getRegionInfo(result);
    if (regionInfo == null) {
      throw new IOException("RegionInfo was null or empty in Meta for " + tableName + ", row=" +
        Bytes.toStringBinary(row));
    }
    return regionInfo;
  }
}
 
Example 3
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 4
Source Project: hgraphdb   File: EdgeIndexModel.java    License: Apache License 2.0 5 votes vote down vote up
private Scan getEdgesScanWithLimit(Vertex vertex, Direction direction, boolean isUnique, String key, String label,
                                   Object fromValue, int limit, boolean reversed) {
    LOGGER.trace("Executing Scan, type: {}, id: {}", "key-limit", vertex.id());

    byte[] prefix = serializeForRead(vertex, direction, isUnique, key, label, null);
    byte[] startRow = fromValue != null
            ? serializeForRead(vertex, direction, isUnique, key, label, fromValue)
            : prefix;
    byte[] stopRow = HConstants.EMPTY_END_ROW;
    if (graph.configuration().getInstanceType() == HBaseGraphConfiguration.InstanceType.BIGTABLE) {
        if (reversed) {
            throw new UnsupportedOperationException("Reverse scans not supported by Bigtable");
        } else {
            // PrefixFilter in Bigtable does not automatically stop
            // See https://github.com/GoogleCloudPlatform/cloud-bigtable-client/issues/1087
            stopRow = HBaseGraphUtils.incrementBytes(prefix);
        }
    }
    if (reversed) startRow = HBaseGraphUtils.incrementBytes(startRow);
    Scan scan = new Scan(startRow, stopRow);
    FilterList filterList = new FilterList();
    filterList.addFilter(new PrefixFilter(prefix));
    filterList.addFilter(new PageFilter(limit));
    scan.setFilter(filterList);
    scan.setReversed(reversed);
    return scan;
}
 
Example 5
Source Project: phoenix   File: ScanUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void setupReverseScan(Scan scan) {
    if (isReversed(scan)) {
        byte[] startRow = scan.getStartRow();
        byte[] stopRow = scan.getStopRow();
        byte[] newStartRow = startRow;
        byte[] newStopRow = stopRow;
        if (startRow.length != 0) {
            /*
             * Must get previous key because this is going from an inclusive start key to an exclusive stop key, and
             * we need the start key to be included. We get the previous key by decrementing the last byte by one.
             * However, with variable length data types, we need to fill with the max byte value, otherwise, if the
             * start key is 'ab', we lower it to 'aa' which would cause 'aab' to be included (which isn't correct).
             * So we fill with a 0xFF byte to prevent this. A single 0xFF would be enough for our primitive types (as
             * that byte wouldn't occur), but for an arbitrary VARBINARY key we can't know how many bytes to tack
             * on. It's lame of HBase to force us to do this.
             */
            newStartRow = Arrays.copyOf(startRow, startRow.length + MAX_FILL_LENGTH_FOR_PREVIOUS_KEY.length);
            if (ByteUtil.previousKey(newStartRow, startRow.length)) {
                System.arraycopy(MAX_FILL_LENGTH_FOR_PREVIOUS_KEY, 0, newStartRow, startRow.length, MAX_FILL_LENGTH_FOR_PREVIOUS_KEY.length);
            } else {
                newStartRow = HConstants.EMPTY_START_ROW;
            }
        }
        if (stopRow.length != 0) {
            // Must add null byte because we need the start to be exclusive while it was inclusive
            newStopRow = ByteUtil.concat(stopRow, QueryConstants.SEPARATOR_BYTE_ARRAY);
        }
        scan.setStartRow(newStopRow);
        scan.setStopRow(newStartRow);
        scan.setReversed(true);
    }
}
 
Example 6
Source Project: pinpoint   File: HbaseAgentInfoDao.java    License: Apache License 2.0 5 votes vote down vote up
private Scan createScanForInitialAgentInfo(String agentId) {
    Scan scan = new Scan();
    byte[] agentIdBytes = Bytes.toBytes(agentId);
    byte[] reverseStartKey = RowKeyUtils.concatFixedByteAndLong(agentIdBytes, HbaseTableConstatns.AGENT_NAME_MAX_LEN, Long.MAX_VALUE);
    scan.setStartRow(reverseStartKey);
    scan.setReversed(true);
    scan.setMaxVersions(1);
    scan.setCaching(SCANNER_CACHING);
    return scan;
}
 
Example 7
Source Project: hbase   File: ThriftHBaseServiceHandler.java    License: Apache License 2.0 5 votes vote down vote up
private Result getReverseScanResult(byte[] tableName, byte[] row, byte[] family)
    throws IOException {
  Scan scan = new Scan().withStartRow(row);
  scan.setReversed(true);
  scan.addFamily(family);
  scan.withStartRow(row);
  try (Table table = getTable(tableName);
       ResultScanner scanner = table.getScanner(scan)) {
    return scanner.next();
  }
}
 
Example 8
@Test
public void testReverseScanWithPadding() throws Exception {
  byte[] terminator = new byte[] { -1 };
  byte[] row1 = Bytes.add(invert(Bytes.toBytes("a")), terminator);
  byte[] row2 = Bytes.add(invert(Bytes.toBytes("ab")), terminator);
  byte[] row3 = Bytes.add(invert(Bytes.toBytes("b")), terminator);

  Put put1 = new Put(row1);
  put1.addColumn(cfName, cqName, HConstants.EMPTY_BYTE_ARRAY);
  Put put2 = new Put(row2);
  put2.addColumn(cfName, cqName, HConstants.EMPTY_BYTE_ARRAY);
  Put put3 = new Put(row3);
  put3.addColumn(cfName, cqName, HConstants.EMPTY_BYTE_ARRAY);

  region.put(put1);
  region.put(put2);
  region.put(put3);
  region.flush(true);
  Scan scan = new Scan();
  scan.setCacheBlocks(false);
  scan.setReversed(true);
  scan.setFilter(new FirstKeyOnlyFilter());
  scan.addFamily(cfName);
  RegionScanner scanner = region.getScanner(scan);
  List<Cell> res = new ArrayList<>();
  int count = 1;
  while (scanner.next(res)) {
    count++;
  }
  assertEquals(3, count);
}
 
Example 9
Source Project: hbase   File: HBaseTestingUtility.java    License: Apache License 2.0 5 votes vote down vote up
public Result getClosestRowBefore(Region r, byte[] row, byte[] family) throws IOException {
  Scan scan = new Scan().withStartRow(row);
  scan.setSmall(true);
  scan.setCaching(1);
  scan.setReversed(true);
  scan.addFamily(family);
  try (RegionScanner scanner = r.getScanner(scan)) {
    List<Cell> cells = new ArrayList<>(1);
    scanner.next(cells);
    if (r.getRegionInfo().isMetaRegion() && !isTargetTable(row, cells.get(0))) {
      return null;
    }
    return Result.create(cells);
  }
}
 
Example 10
/**
 * Test the method {@link Result#createCompleteResult(Iterable)}
 * @throws Exception
 */
@Test
public void testPartialResultsReassembly() throws Exception {
  Scan scan = new Scan();
  testPartialResultsReassembly(scan);
  scan.setReversed(true);
  testPartialResultsReassembly(scan);
}
 
Example 11
Source Project: hbase   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());
}
 
Example 12
Source Project: hbase   File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testReverseMultiRowRangeFilterIncludingMaxRow() throws IOException {
  tableName = TableName.valueOf(name.getMethodName());
  Table ht = TEST_UTIL.createTable(tableName, family);
  for (String rowkey : Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h")) {
    byte[] row = Bytes.toBytes(rowkey);
    Put p = new Put(row);
    p.addColumn(family, qf, value);
    ht.put(p);
  }
  TEST_UTIL.flush();

  Scan scan = new Scan();
  scan.setReversed(true);
  List<RowRange> ranges = Arrays.asList(
      new RowRange(Bytes.toBytes("b"), true, Bytes.toBytes("c"), true),
      new RowRange(Bytes.toBytes("f"), true, Bytes.toBytes("h"), true)
  );
  MultiRowRangeFilter filter = new MultiRowRangeFilter(ranges);
  scan.setFilter(filter);

  List<String> expected = Arrays.asList("h", "g", "f", "c", "b");
  List<String> actual = new ArrayList<>();
  for (Cell cell : getResults(ht, scan)) {
    actual.add(Bytes.toString(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()));
  }

  assertEquals(expected, actual);
}
 
Example 13
Source Project: phoenix   File: ScanUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void setupReverseScan(Scan scan) {
    if (isReversed(scan)) {
        byte[] newStartRow = getReversedRow(scan.getStartRow());
        byte[] newStopRow = getReversedRow(scan.getStopRow());
        scan.setStartRow(newStopRow);
        scan.setStopRow(newStartRow);
        scan.setReversed(true);
    }
}
 
Example 14
Source Project: hbase   File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testReverseMultiRowRangeFilterIncludingMinAndMaxRow() throws IOException {
  tableName = TableName.valueOf(name.getMethodName());
  Table ht = TEST_UTIL.createTable(tableName, family);
  for (String rowkey : Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h")) {
    byte[] row = Bytes.toBytes(rowkey);
    Put p = new Put(row);
    p.addColumn(family, qf, value);
    ht.put(p);
  }
  TEST_UTIL.flush();

  Scan scan = new Scan();
  scan.setReversed(true);
  List<RowRange> ranges = Arrays.asList(
      new RowRange(Bytes.toBytes("a"), true, Bytes.toBytes("c"), true),
      new RowRange(Bytes.toBytes("f"), true, Bytes.toBytes("h"), true)
  );
  MultiRowRangeFilter filter = new MultiRowRangeFilter(ranges);
  scan.setFilter(filter);

  List<String> expected = Arrays.asList("h", "g", "f", "c", "b", "a");
  List<String> actual = new ArrayList<>();
  for (Cell cell : getResults(ht, scan)) {
    actual.add(Bytes.toString(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()));
  }

  assertEquals(expected, actual);
}
 
Example 15
@Test
public void testReversedPartialResultWhenRegionMove() throws IOException {
  Table table = createTestTable(TableName.valueOf(name.getMethodName()),
      ROWS, FAMILIES, QUALIFIERS, VALUE);

  moveRegion(table, 1);

  Scan scan = new Scan();
  scan.setMaxResultSize(1);
  scan.setAllowPartialResults(true);
  scan.setReversed(true);
  ResultScanner scanner = table.getScanner(scan);
  for (int i = 0; i < NUM_FAMILIES * NUM_QUALIFIERS-1; i++) {
    scanner.next();
  }
  Result result1 = scanner.next();
  assertEquals(1, result1.rawCells().length);
  Cell c1 = result1.rawCells()[0];
  assertCell(c1, ROWS[NUM_ROWS-1], FAMILIES[NUM_FAMILIES - 1], QUALIFIERS[NUM_QUALIFIERS - 1]);
  assertFalse(result1.mayHaveMoreCellsInRow());

  moveRegion(table, 2);

  Result result2 = scanner.next();
  assertEquals(1, result2.rawCells().length);
  Cell c2 = result2.rawCells()[0];
  assertCell(c2, ROWS[NUM_ROWS-2], FAMILIES[0], QUALIFIERS[0]);
  assertTrue(result2.mayHaveMoreCellsInRow());

  moveRegion(table, 3);

  Result result3 = scanner.next();
  assertEquals(1, result3.rawCells().length);
  Cell c3 = result3.rawCells()[0];
  assertCell(c3, ROWS[NUM_ROWS-2], FAMILIES[0], QUALIFIERS[1]);
  assertTrue(result3.mayHaveMoreCellsInRow());

}
 
Example 16
Source Project: hbase   File: TestFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testInclusiveStopFilterWithReverseScan() throws IOException {

  // Grab rows from group one

  // If we just use start/stop row, we get total/2 - 1 rows
  long expectedRows = (this.numRows / 2) - 1;
  long expectedKeys = this.colsPerRow;
  Scan s = new Scan().withStartRow(Bytes.toBytes("testRowOne-3"))
    .withStopRow(Bytes.toBytes("testRowOne-0"));
  s.setReversed(true);
  verifyScan(s, expectedRows, expectedKeys);

  // Now use start row with inclusive stop filter
  expectedRows = this.numRows / 2;
  s = new Scan().withStartRow(Bytes.toBytes("testRowOne-3"));
  s.setReversed(true);
  s.setFilter(new InclusiveStopFilter(Bytes.toBytes("testRowOne-0")));
  verifyScan(s, expectedRows, expectedKeys);

  // Grab rows from group two

  // If we just use start/stop row, we get total/2 - 1 rows
  expectedRows = (this.numRows / 2) - 1;
  expectedKeys = this.colsPerRow;
  s = new Scan().withStartRow(Bytes.toBytes("testRowTwo-3"))
    .withStopRow(Bytes.toBytes("testRowTwo-0"));
  s.setReversed(true);
  verifyScan(s, expectedRows, expectedKeys);

  // Now use start row with inclusive stop filter
  expectedRows = this.numRows / 2;
  s = new Scan().withStartRow(Bytes.toBytes("testRowTwo-3"));
  s.setReversed(true);
  s.setFilter(new InclusiveStopFilter(Bytes.toBytes("testRowTwo-0")));
  verifyScan(s, expectedRows, expectedKeys);

}
 
Example 17
@Test
public void testReverseScanWithoutPadding() throws Exception {
  byte[] row1 = Bytes.toBytes("a");
  byte[] row2 = Bytes.toBytes("ab");
  byte[] row3 = Bytes.toBytes("b");

  Put put1 = new Put(row1);
  put1.addColumn(cfName, cqName, HConstants.EMPTY_BYTE_ARRAY);
  Put put2 = new Put(row2);
  put2.addColumn(cfName, cqName, HConstants.EMPTY_BYTE_ARRAY);
  Put put3 = new Put(row3);
  put3.addColumn(cfName, cqName, HConstants.EMPTY_BYTE_ARRAY);

  region.put(put1);
  region.put(put2);
  region.put(put3);
  region.flush(true);
  Scan scan = new Scan();
  scan.setCacheBlocks(false);
  scan.setReversed(true);
  scan.setFilter(new FirstKeyOnlyFilter());
  scan.addFamily(cfName);
  RegionScanner scanner = region.getScanner(scan);
  List<Cell> res = new ArrayList<>();
  int count = 1;
  while (scanner.next(res)) {
    count++;
  }
  assertEquals("b", Bytes.toString(res.get(0).getRowArray(), res.get(0).getRowOffset(),
      res.get(0).getRowLength()));
  assertEquals("ab", Bytes.toString(res.get(1).getRowArray(), res.get(1).getRowOffset(),
      res.get(1).getRowLength()));
  assertEquals("a", Bytes.toString(res.get(2).getRowArray(), res.get(2).getRowOffset(),
      res.get(2).getRowLength()));
  assertEquals(3, count);
}
 
Example 18
Source Project: hbase   File: ThriftHBaseServiceHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public int scannerOpenWithScan(ByteBuffer tableName, TScan tScan,
    Map<ByteBuffer, ByteBuffer> attributes)
    throws IOError {

  Table table = null;
  try {
    table = getTable(tableName);
    Scan scan = new Scan();
    addAttributes(scan, attributes);
    if (tScan.isSetStartRow()) {
      scan.withStartRow(tScan.getStartRow());
    }
    if (tScan.isSetStopRow()) {
      scan.withStopRow(tScan.getStopRow());
    }
    if (tScan.isSetTimestamp()) {
      scan.setTimeRange(0, tScan.getTimestamp());
    }
    if (tScan.isSetCaching()) {
      scan.setCaching(tScan.getCaching());
    }
    if (tScan.isSetBatchSize()) {
      scan.setBatch(tScan.getBatchSize());
    }
    if (tScan.isSetColumns() && !tScan.getColumns().isEmpty()) {
      for(ByteBuffer column : tScan.getColumns()) {
        byte [][] famQf = CellUtil.parseColumn(getBytes(column));
        if(famQf.length == 1) {
          scan.addFamily(famQf[0]);
        } else {
          scan.addColumn(famQf[0], famQf[1]);
        }
      }
    }
    if (tScan.isSetFilterString()) {
      ParseFilter parseFilter = new ParseFilter();
      scan.setFilter(
          parseFilter.parseFilterString(tScan.getFilterString()));
    }
    if (tScan.isSetReversed()) {
      scan.setReversed(tScan.isReversed());
    }
    if (tScan.isSetCacheBlocks()) {
      scan.setCacheBlocks(tScan.isCacheBlocks());
    }
    return addScanner(table.getScanner(scan), tScan.sortColumns);
  } catch (IOException e) {
    LOG.warn(e.getMessage(), e);
    throw getIOError(e);
  } finally{
    closeTable(table);
  }
}
 
Example 19
Source Project: hbase   File: TestReversibleScanners.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testReversibleStoreScanner() throws IOException {
  // write data to one memstore and two store files
  FileSystem fs = TEST_UTIL.getTestFileSystem();
  Path hfilePath = new Path(new Path(
      TEST_UTIL.getDataTestDir("testReversibleStoreScanner"), "regionname"),
      "familyname");
  CacheConfig cacheConf = new CacheConfig(TEST_UTIL.getConfiguration());
  HFileContextBuilder hcBuilder = new HFileContextBuilder();
  hcBuilder.withBlockSize(2 * 1024);
  HFileContext hFileContext = hcBuilder.build();
  StoreFileWriter writer1 = new StoreFileWriter.Builder(
      TEST_UTIL.getConfiguration(), cacheConf, fs).withOutputDir(
      hfilePath).withFileContext(hFileContext).build();
  StoreFileWriter writer2 = new StoreFileWriter.Builder(
      TEST_UTIL.getConfiguration(), cacheConf, fs).withOutputDir(
      hfilePath).withFileContext(hFileContext).build();

  MemStore memstore = new DefaultMemStore();
  writeMemstoreAndStoreFiles(memstore, new StoreFileWriter[] { writer1,
      writer2 });

  HStoreFile sf1 = new HStoreFile(fs, writer1.getPath(), TEST_UTIL.getConfiguration(), cacheConf,
      BloomType.NONE, true);

  HStoreFile sf2 = new HStoreFile(fs, writer2.getPath(), TEST_UTIL.getConfiguration(), cacheConf,
      BloomType.NONE, true);

  ScanInfo scanInfo =
      new ScanInfo(TEST_UTIL.getConfiguration(), FAMILYNAME, 0, Integer.MAX_VALUE, Long.MAX_VALUE,
          KeepDeletedCells.FALSE, HConstants.DEFAULT_BLOCKSIZE, 0, CellComparatorImpl.COMPARATOR, false);

  // Case 1.Test a full reversed scan
  Scan scan = new Scan();
  scan.setReversed(true);
  StoreScanner storeScanner =
      getReversibleStoreScanner(memstore, sf1, sf2, scan, scanInfo, MAXMVCC);
  verifyCountAndOrder(storeScanner, QUALSIZE * ROWSIZE, ROWSIZE, false);

  // Case 2.Test reversed scan with a specified start row
  int startRowNum = ROWSIZE / 2;
  byte[] startRow = ROWS[startRowNum];
  scan.withStartRow(startRow);
  storeScanner = getReversibleStoreScanner(memstore, sf1, sf2, scan, scanInfo, MAXMVCC);
  verifyCountAndOrder(storeScanner, QUALSIZE * (startRowNum + 1),
      startRowNum + 1, false);

  // Case 3.Test reversed scan with a specified start row and specified
  // qualifiers
  assertTrue(QUALSIZE > 2);
  scan.addColumn(FAMILYNAME, QUALS[0]);
  scan.addColumn(FAMILYNAME, QUALS[2]);
  storeScanner = getReversibleStoreScanner(memstore, sf1, sf2, scan, scanInfo, MAXMVCC);
  verifyCountAndOrder(storeScanner, 2 * (startRowNum + 1), startRowNum + 1,
      false);

  // Case 4.Test reversed scan with mvcc based on case 3
  for (int readPoint = 0; readPoint < MAXMVCC; readPoint++) {
    LOG.info("Setting read point to " + readPoint);
    storeScanner = getReversibleStoreScanner(memstore, sf1, sf2, scan, scanInfo, readPoint);
    int expectedRowCount = 0;
    int expectedKVCount = 0;
    for (int i = startRowNum; i >= 0; i--) {
      int kvCount = 0;
      if (makeMVCC(i, 0) <= readPoint) {
        kvCount++;
      }
      if (makeMVCC(i, 2) <= readPoint) {
        kvCount++;
      }
      if (kvCount > 0) {
        expectedRowCount++;
        expectedKVCount += kvCount;
      }
    }
    verifyCountAndOrder(storeScanner, expectedKVCount, expectedRowCount,
        false);
  }
}
 
Example 20
Source Project: nifi   File: HBase_2_ClientService.java    License: Apache License 2.0 4 votes vote down vote up
protected ResultScanner getResults(final Table table, final String startRow, final String endRow, final String filterExpression, final Long timerangeMin, final Long timerangeMax,
        final Integer limitRows, final Boolean isReversed, final Boolean blockCache, final Collection<Column> columns, List<String> authorizations)  throws IOException {
    final Scan scan = new Scan();
    if (!StringUtils.isBlank(startRow)){
        scan.setStartRow(startRow.getBytes(StandardCharsets.UTF_8));
    }
    if (!StringUtils.isBlank(endRow)){
        scan.setStopRow(   endRow.getBytes(StandardCharsets.UTF_8));
    }

    if (authorizations != null && authorizations.size() > 0) {
        scan.setAuthorizations(new Authorizations(authorizations));
    }

    Filter filter = null;
    if (columns != null) {
        for (Column col : columns) {
            if (col.getQualifier() == null) {
                scan.addFamily(col.getFamily());
            } else {
                scan.addColumn(col.getFamily(), col.getQualifier());
            }
        }
    }
    if (!StringUtils.isBlank(filterExpression)) {
        ParseFilter parseFilter = new ParseFilter();
        filter = parseFilter.parseFilterString(filterExpression);
    }
    if (filter != null){
        scan.setFilter(filter);
    }

    if (timerangeMin != null && timerangeMax != null){
        scan.setTimeRange(timerangeMin, timerangeMax);
    }

    // ->>> reserved for HBase v 2 or later
    //if (limitRows != null && limitRows > 0){
    //    scan.setLimit(limitRows)
    //}

    if (isReversed != null){
        scan.setReversed(isReversed);
    }

    scan.setCacheBlocks(blockCache);

    return table.getScanner(scan);
}