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

The following examples show how to use org.apache.hadoop.hbase.client.Scan#getLimit() . 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: RequestConverter.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Create a protocol buffer ScanRequest for a client Scan
 *
 * @param regionName
 * @param scan
 * @param numberOfRows
 * @param closeScanner
 * @return a scan request
 * @throws IOException
 */
public static ScanRequest buildScanRequest(byte[] regionName, Scan scan, int numberOfRows,
    boolean closeScanner) throws IOException {
  ScanRequest.Builder builder = ScanRequest.newBuilder();
  RegionSpecifier region = buildRegionSpecifier(RegionSpecifierType.REGION_NAME, regionName);
  builder.setNumberOfRows(numberOfRows);
  builder.setCloseScanner(closeScanner);
  builder.setRegion(region);
  builder.setScan(ProtobufUtil.toScan(scan));
  builder.setClientHandlesPartials(true);
  builder.setClientHandlesHeartbeats(true);
  builder.setTrackScanMetrics(scan.isScanMetricsEnabled());
  if (scan.getLimit() > 0) {
    builder.setLimitOfRows(scan.getLimit());
  }
  return builder.build();
}
 
Example 2
Source File: ScannerModel.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * @param scan the scan specification
 * @throws Exception
 */
public static ScannerModel fromScan(Scan scan) throws Exception {
  ScannerModel model = new ScannerModel();
  model.setStartRow(scan.getStartRow());
  model.setEndRow(scan.getStopRow());
  Map<byte [], NavigableSet<byte []>> families = scan.getFamilyMap();
  if (families != null) {
    for (Map.Entry<byte [], NavigableSet<byte []>> entry : families.entrySet()) {
      if (entry.getValue() != null) {
        for (byte[] qualifier: entry.getValue()) {
          model.addColumn(Bytes.add(entry.getKey(), COLUMN_DIVIDER, qualifier));
        }
      } else {
        model.addColumn(entry.getKey());
      }
    }
  }
  model.setStartTime(scan.getTimeRange().getMin());
  model.setEndTime(scan.getTimeRange().getMax());
  int caching = scan.getCaching();
  if (caching > 0) {
    model.setCaching(caching);
  }
  int batch = scan.getBatch();
  if (batch > 0) {
    model.setBatch(batch);
  }
  int maxVersions = scan.getMaxVersions();
  if (maxVersions > 0) {
    model.setMaxVersions(maxVersions);
  }
  if (scan.getLimit() > 0) {
    model.setLimit(scan.getLimit());
  }
  Filter filter = scan.getFilter();
  if (filter != null) {
    model.setFilter(stringifyFilter(filter));
  }
  // Add the visbility labels if found in the attributes
  Authorizations authorizations = scan.getAuthorizations();
  if (authorizations != null) {
    List<String> labels = authorizations.getLabels();
    for (String label : labels) {
      model.addLabel(label);
    }
  }
  return model;
}