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

The following examples show how to use org.apache.hadoop.hbase.client.Scan#getTimeRange() . 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: UserScanQueryMatcher.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected UserScanQueryMatcher(Scan scan, ScanInfo scanInfo, ColumnTracker columns,
    boolean hasNullColumn, long oldestUnexpiredTS, long now) {
  super(createStartKey(scan, scanInfo), scanInfo, columns, oldestUnexpiredTS, now);
  this.hasNullColumn = hasNullColumn;
  this.filter = scan.getFilter();
  if (this.filter != null) {
    this.versionsAfterFilter =
        scan.isRaw() ? scan.getMaxVersions() : Math.min(scan.getMaxVersions(),
          scanInfo.getMaxVersions());
  } else {
    this.versionsAfterFilter = 0;
  }
  this.stopRow = scan.getStopRow();
  TimeRange timeRange = scan.getColumnFamilyTimeRange().get(scanInfo.getFamily());
  if (timeRange == null) {
    this.tr = scan.getTimeRange();
  } else {
    this.tr = timeRange;
  }
}
 
Example 2
Source File: BaseScannerRegionObserver.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Override
public void preScannerOpen(org.apache.hadoop.hbase.coprocessor.ObserverContext<RegionCoprocessorEnvironment> c,
        Scan scan) throws IOException {
    byte[] txnScn = scan.getAttribute(TX_SCN);
    if (txnScn!=null) {
        TimeRange timeRange = scan.getTimeRange();
        scan.setTimeRange(timeRange.getMin(), Bytes.toLong(txnScn));
    }
    if (isRegionObserverFor(scan)) {
        // For local indexes, we need to throw if out of region as we'll get inconsistent
        // results otherwise while in other cases, it may just mean out client-side data
        // on region boundaries is out of date and can safely be ignored.
        if (!skipRegionBoundaryCheck(scan) || ScanUtil.isLocalIndex(scan)) {
            throwIfScanOutOfRegion(scan, c.getEnvironment().getRegion());
        }
        // Muck with the start/stop row of the scan and set as reversed at the
        // last possible moment. You need to swap the start/stop and make the
        // start exclusive and the stop inclusive.
        ScanUtil.setupReverseScan(scan);
    }
}
 
Example 3
Source File: StoreFileScanner.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public boolean shouldUseScanner(Scan scan, HStore store, long oldestUnexpiredTS) {
  // if the file has no entries, no need to validate or create a scanner.
  byte[] cf = store.getColumnFamilyDescriptor().getName();
  TimeRange timeRange = scan.getColumnFamilyTimeRange().get(cf);
  if (timeRange == null) {
    timeRange = scan.getTimeRange();
  }
  return reader.passesTimerangeFilter(timeRange, oldestUnexpiredTS) && reader
      .passesKeyRangeFilter(scan) && reader.passesBloomFilter(scan, scan.getFamilyMap().get(cf));
}
 
Example 4
Source File: TTable.java    From phoenix-omid with Apache License 2.0 4 votes vote down vote up
private void throwExceptionIfOpSetsTimerange(Scan scanOperation) {
    TimeRange tr = scanOperation.getTimeRange();
    checkTimerangeIsSetToDefaultValuesOrThrowException(tr);
}
 
Example 5
Source File: TestSerialization.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testScan() throws Exception {

  byte[] startRow = Bytes.toBytes("startRow");
  byte[] stopRow = Bytes.toBytes("stopRow");
  byte[] fam = Bytes.toBytes("fam");
  byte[] qf1 = Bytes.toBytes("qf1");

  long ts = System.currentTimeMillis();
  int maxVersions = 2;

  Scan scan = new Scan().withStartRow(startRow).withStopRow(stopRow);
  scan.addColumn(fam, qf1);
  scan.setTimeRange(ts, ts + 1);
  scan.readVersions(maxVersions);

  ClientProtos.Scan scanProto = ProtobufUtil.toScan(scan);
  Scan desScan = ProtobufUtil.toScan(scanProto);

  assertTrue(Bytes.equals(scan.getStartRow(), desScan.getStartRow()));
  assertTrue(Bytes.equals(scan.getStopRow(), desScan.getStopRow()));
  assertEquals(scan.getCacheBlocks(), desScan.getCacheBlocks());
  Set<byte[]> set = null;
  Set<byte[]> desSet = null;

  for (Map.Entry<byte[], NavigableSet<byte[]>> entry : scan.getFamilyMap().entrySet()) {
    assertTrue(desScan.getFamilyMap().containsKey(entry.getKey()));
    set = entry.getValue();
    desSet = desScan.getFamilyMap().get(entry.getKey());
    for (byte[] column : set) {
      assertTrue(desSet.contains(column));
    }

    // Test filters are serialized properly.
    scan = new Scan().withStartRow(startRow);
    final String name = "testScan";
    byte[] prefix = Bytes.toBytes(name);
    scan.setFilter(new PrefixFilter(prefix));
    scanProto = ProtobufUtil.toScan(scan);
    desScan = ProtobufUtil.toScan(scanProto);
    Filter f = desScan.getFilter();
    assertTrue(f instanceof PrefixFilter);
  }

  assertEquals(scan.getMaxVersions(), desScan.getMaxVersions());
  TimeRange tr = scan.getTimeRange();
  TimeRange desTr = desScan.getTimeRange();
  assertEquals(tr.getMax(), desTr.getMax());
  assertEquals(tr.getMin(), desTr.getMin());
}