Java Code Examples for org.apache.hadoop.hbase.client.Get#setTimeRange()

The following examples show how to use org.apache.hadoop.hbase.client.Get#setTimeRange() . 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: PcapGetterHBaseImpl.java    From opensoc-streaming with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the time range on get.
 * 
 * @param get
 *          the get
 * @param startTime
 *          the start time
 * @param endTime
 *          the end time
 * @throws IOException
 *           Signals that an I/O exception has occurred.
 */
private void setTimeRangeOnGet(Get get, long startTime, long endTime)
    throws IOException {
  boolean setTimeRange = true;
  if (startTime < 0 && endTime < 0) {
    setTimeRange = false;
  }
  if (setTimeRange) {
    if (startTime < 0) {
      startTime = 0;
    } else {
      startTime = PcapHelper.convertToDataCreationTimeUnit(startTime);
    }
    if (endTime < 0) {
      endTime = Long.MAX_VALUE;
    } else {
      endTime = PcapHelper.convertToDataCreationTimeUnit(endTime);
    }
    Assert.isTrue(startTime < endTime,
        "startTime value must be less than endTime value");
    get.setTimeRange(startTime, endTime);
  }
}
 
Example 2
Source File: RSRpcServices.java    From hbase with Apache License 2.0 6 votes vote down vote up
private static Get toGet(final Mutation mutation) throws IOException {
  if(!(mutation instanceof Increment) && !(mutation instanceof Append)) {
    throw new AssertionError("mutation must be a instance of Increment or Append");
  }
  Get get = new Get(mutation.getRow());
  CellScanner cellScanner = mutation.cellScanner();
  while (!cellScanner.advance()) {
    Cell cell = cellScanner.current();
    get.addColumn(CellUtil.cloneFamily(cell), CellUtil.cloneQualifier(cell));
  }
  if (mutation instanceof Increment) {
    // Increment
    Increment increment = (Increment) mutation;
    get.setTimeRange(increment.getTimeRange().getMin(), increment.getTimeRange().getMax());
  } else {
    // Append
    Append append = (Append) mutation;
    get.setTimeRange(append.getTimeRange().getMin(), append.getTimeRange().getMax());
  }
  for (Entry<String, byte[]> entry : mutation.getAttributesMap().entrySet()) {
    get.setAttribute(entry.getKey(), entry.getValue());
  }
  return get;
}
 
Example 3
Source File: PcapGetterHBaseImpl.java    From opensoc-streaming with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the time range on get.
 * 
 * @param get
 *          the get
 * @param startTime
 *          the start time
 * @param endTime
 *          the end time
 * @throws IOException
 *           Signals that an I/O exception has occurred.
 */
private void setTimeRangeOnGet(Get get, long startTime, long endTime)
    throws IOException {
  boolean setTimeRange = true;
  if (startTime < 0 && endTime < 0) {
    setTimeRange = false;
  }
  if (setTimeRange) {
    if (startTime < 0) {
      startTime = 0;
    } else {
      startTime = PcapHelper.convertToDataCreationTimeUnit(startTime);
    }
    if (endTime < 0) {
      endTime = Long.MAX_VALUE;
    } else {
      endTime = PcapHelper.convertToDataCreationTimeUnit(endTime);
    }
    Assert.isTrue(startTime < endTime,
        "startTime value must be less than endTime value");
    get.setTimeRange(startTime, endTime);
  }
}
 
Example 4
Source File: SIObserver.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException{
    checkAccess();

    try {
        SpliceLogUtils.trace(LOG,"preGet %s",get);
        if(tableEnvMatch && shouldUseSI(get)){
            get.setMaxVersions();
            get.setTimeRange(0L,Long.MAX_VALUE);
            assert (get.getMaxVersions()==Integer.MAX_VALUE);
            addSIFilterToGet(get);
        }
        SpliceLogUtils.trace(LOG,"preGet after %s",get);

    } catch (Throwable t) {
        throw CoprocessorUtils.getIOException(t);
    }
}
 
Example 5
Source File: ThriftHBaseServiceHandler.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Note: this internal interface is slightly different from public APIs in regard to handling
 * of the qualifier. Here we differ from the public Java API in that null != byte[0]. Rather,
 * we respect qual == null as a request for the entire column family. The caller (
 * {@link #getVerTs(ByteBuffer, ByteBuffer, ByteBuffer, long, int, Map)}) interface IS
 * consistent in that the column is parse like normal.
 */
protected List<TCell> getVerTs(ByteBuffer tableName, ByteBuffer row, byte[] family,
    byte[] qualifier, long timestamp, int numVersions, Map<ByteBuffer, ByteBuffer> attributes)
    throws IOError {

  Table table = null;
  try {
    table = getTable(tableName);
    Get get = new Get(getBytes(row));
    addAttributes(get, attributes);
    if (null == qualifier) {
      get.addFamily(family);
    } else {
      get.addColumn(family, qualifier);
    }
    get.setTimeRange(0, timestamp);
    get.readVersions(numVersions);
    Result result = table.get(get);
    return ThriftUtilities.cellFromHBase(result.rawCells());
  } catch (IOException e) {
    LOG.warn(e.getMessage(), e);
    throw getIOError(e);
  } finally{
    closeTable(table);
  }
}
 
Example 6
Source File: HbOperate.java    From tddl5 with Apache License 2.0 6 votes vote down vote up
private Get buildGet(HbData opData) throws IOException {
    Get get = new Get(opData.getRowKey());

    if (opData.getMaxVersion() > 0) {
        get.setMaxVersions(opData.getMaxVersion());
    }

    for (HbColumn column : opData.getColumns()) {
        if (column.getTimestamp() > 0) {
            get.setTimeStamp(column.getTimestamp());
        } else if (opData.getStartTime() > 0 && opData.getEndTime() > 0
                   && opData.getEndTime() > opData.getStartTime()) {
            get.setTimeRange(opData.getStartTime(), opData.getEndTime());
        }

        if (StringUtils.isNotEmpty(column.getColumnFamily()) && StringUtils.isNotEmpty(column.getColumnName())) {
            get.addColumn(Bytes.toBytes(column.getColumnFamily()), Bytes.toBytes(column.getColumnName()));
        }
    }
    return get;
}
 
Example 7
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
@Override
public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results)
  throws IOException {
  Transaction tx = getFromOperation(get);
  if (tx != null) {
    projectFamilyDeletes(get);
    get.setMaxVersions();
    get.setTimeRange(TxUtils.getOldestVisibleTimestamp(ttlByFamily, tx, readNonTxnData),
                     TxUtils.getMaxVisibleTimestamp(tx));
    Filter newFilter = getTransactionFilter(tx, ScanType.USER_SCAN, get.getFilter());
    get.setFilter(newFilter);
  }
}
 
Example 8
Source File: TestSerialization.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testGet() throws Exception {
  byte[] row = Bytes.toBytes("row");
  byte[] fam = Bytes.toBytes("fam");
  byte[] qf1 = Bytes.toBytes("qf1");

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

  Get get = new Get(row);
  get.addColumn(fam, qf1);
  get.setTimeRange(ts, ts + 1);
  get.readVersions(maxVersions);

  ClientProtos.Get getProto = ProtobufUtil.toGet(get);
  Get desGet = ProtobufUtil.toGet(getProto);

  assertTrue(Bytes.equals(get.getRow(), desGet.getRow()));
  Set<byte[]> set = null;
  Set<byte[]> desSet = null;

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

  assertEquals(get.getMaxVersions(), desGet.getMaxVersions());
  TimeRange tr = get.getTimeRange();
  TimeRange desTr = desGet.getTimeRange();
  assertEquals(tr.getMax(), desTr.getMax());
  assertEquals(tr.getMin(), desTr.getMin());
}
 
Example 9
Source File: TestKeepDeletes.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void checkGet(Region region, byte[] row, byte[] fam, byte[] col,
    long time, byte[]... vals) throws IOException {
  Get g = new Get(row);
  g.addColumn(fam, col);
  g.readAllVersions();
  g.setTimeRange(0L, time);
  Result r = region.get(g);
  checkResult(r, fam, col, vals);

}
 
Example 10
Source File: TestCoprocessorScanPolicy.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> c, Get get,
    List<Cell> result) throws IOException {
  TableName tableName = c.getEnvironment().getRegion().getTableDescriptor().getTableName();
  Long ttl = this.ttls.get(tableName);
  if (ttl != null) {
    get.setTimeRange(EnvironmentEdgeManager.currentTime() - ttl, get.getTimeRange().getMax());
  }
  Integer version = this.versions.get(tableName);
  if (version != null) {
    get.readVersions(version);
  }
}
 
Example 11
Source File: StatisticsUtil.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public static Result readRegionStatistics(HTableInterface statsHTable, byte[] tableNameBytes, ImmutableBytesPtr cf, byte[] regionName, long clientTimeStamp)
        throws IOException {
    byte[] prefix = StatisticsUtil.getRowKey(tableNameBytes, cf, regionName);
    Get get = new Get(prefix);
    get.setTimeRange(MetaDataProtocol.MIN_TABLE_TIMESTAMP, clientTimeStamp);
    get.addColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH_BYTES);
    get.addColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, PhoenixDatabaseMetaData.GUIDE_POSTS_BYTES);
    get.addColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, PhoenixDatabaseMetaData.GUIDE_POSTS_ROW_COUNT_BYTES);
    return statsHTable.get(get);
}
 
Example 12
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
@Override
public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results)
  throws IOException {
  Transaction tx = getFromOperation(get);
  if (tx != null) {
    projectFamilyDeletes(get);
    get.setMaxVersions();
    get.setTimeRange(TxUtils.getOldestVisibleTimestamp(ttlByFamily, tx, readNonTxnData),
                     TxUtils.getMaxVisibleTimestamp(tx));
    Filter newFilter = getTransactionFilter(tx, ScanType.USER_SCAN, get.getFilter());
    get.setFilter(newFilter);
  }
}
 
Example 13
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
@Override
public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results)
  throws IOException {
  Transaction tx = getFromOperation(get);
  if (tx != null) {
    projectFamilyDeletes(get);
    get.setMaxVersions();
    get.setTimeRange(TxUtils.getOldestVisibleTimestamp(ttlByFamily, tx, readNonTxnData),
                     TxUtils.getMaxVisibleTimestamp(tx));
    Filter newFilter = getTransactionFilter(tx, ScanType.USER_SCAN, get.getFilter());
    get.setFilter(newFilter);
  }
}
 
Example 14
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
@Override
public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results)
  throws IOException {
  Transaction tx = getFromOperation(get);
  if (tx != null) {
    projectFamilyDeletes(get);
    get.setMaxVersions();
    get.setTimeRange(TxUtils.getOldestVisibleTimestamp(ttlByFamily, tx, readNonTxnData),
                     TxUtils.getMaxVisibleTimestamp(tx));
    Filter newFilter = getTransactionFilter(tx, ScanType.USER_SCAN, get.getFilter());
    get.setFilter(newFilter);
  }
}
 
Example 15
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
@Override
public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results)
    throws IOException {
  Transaction tx = getFromOperation(get);
  if (tx != null) {
    projectFamilyDeletes(get);
    get.setMaxVersions();
    get.setTimeRange(TxUtils.getOldestVisibleTimestamp(ttlByFamily, tx, readNonTxnData),
      TxUtils.getMaxVisibleTimestamp(tx));
    Filter newFilter = getTransactionFilter(tx, ScanType.USER_SCAN, get.getFilter());
    get.setFilter(newFilter);
  }
}
 
Example 16
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
@Override
public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results)
  throws IOException {
  Transaction tx = getFromOperation(get);
  if (tx != null) {
    projectFamilyDeletes(get);
    get.setMaxVersions();
    get.setTimeRange(TxUtils.getOldestVisibleTimestamp(ttlByFamily, tx, readNonTxnData),
                     TxUtils.getMaxVisibleTimestamp(tx));
    Filter newFilter = getTransactionFilter(tx, ScanType.USER_SCAN, get.getFilter());
    get.setFilter(newFilter);
  }
}
 
Example 17
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
@Override
public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results)
  throws IOException {
  Transaction tx = getFromOperation(get);
  if (tx != null) {
    projectFamilyDeletes(get);
    get.setMaxVersions();
    get.setTimeRange(TxUtils.getOldestVisibleTimestamp(ttlByFamily, tx, readNonTxnData),
                     TxUtils.getMaxVisibleTimestamp(tx));
    Filter newFilter = getTransactionFilter(tx, ScanType.USER_SCAN, get.getFilter());
    get.setFilter(newFilter);
  }
}
 
Example 18
Source File: ThriftUtilities.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a {@link Get} (HBase) from a {@link TGet} (Thrift).
 *
 * This ignores any timestamps set on {@link TColumn} objects.
 *
 * @param in the <code>TGet</code> to convert
 *
 * @return <code>Get</code> object
 *
 * @throws IOException if an invalid time range or max version parameter is given
 */
public static Get getFromThrift(TGet in) throws IOException {
  Get out = new Get(in.getRow());

  // Timestamp overwrites time range if both are set
  if (in.isSetTimestamp()) {
    out.setTimestamp(in.getTimestamp());
  } else if (in.isSetTimeRange()) {
    out.setTimeRange(in.getTimeRange().getMinStamp(), in.getTimeRange().getMaxStamp());
  }

  if (in.isSetMaxVersions()) {
    out.readVersions(in.getMaxVersions());
  }

  if (in.isSetFilterString()) {
    ParseFilter parseFilter = new ParseFilter();
    out.setFilter(parseFilter.parseFilterString(in.getFilterString()));
  }

  if (in.isSetAttributes()) {
    addAttributes(out,in.getAttributes());
  }

  if (in.isSetAuthorizations()) {
    out.setAuthorizations(new Authorizations(in.getAuthorizations().getLabels()));
  }

  if (in.isSetConsistency()) {
    out.setConsistency(consistencyFromThrift(in.getConsistency()));
  }

  if (in.isSetTargetReplicaId()) {
    out.setReplicaId(in.getTargetReplicaId());
  }

  if (in.isSetCacheBlocks()) {
    out.setCacheBlocks(in.isCacheBlocks());
  }
  if (in.isSetStoreLimit()) {
    out.setMaxResultsPerColumnFamily(in.getStoreLimit());
  }
  if (in.isSetStoreOffset()) {
    out.setRowOffsetPerColumnFamily(in.getStoreOffset());
  }
  if (in.isSetExistence_only()) {
    out.setCheckExistenceOnly(in.isExistence_only());
  }

  if (in.isSetColumns()) {
    for (TColumn column : in.getColumns()) {
      if (column.isSetQualifier()) {
        out.addColumn(column.getFamily(), column.getQualifier());
      } else {
        out.addFamily(column.getFamily());
      }
    }
  }

  if (in.isSetFilterBytes()) {
    out.setFilter(filterFromThrift(in.getFilterBytes()));
  }
  return out;
}
 
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);
}
 
Example 20
Source File: RowResultGenerator.java    From hbase with Apache License 2.0 4 votes vote down vote up
public RowResultGenerator(final String tableName, final RowSpec rowspec,
    final Filter filter, final boolean cacheBlocks)
    throws IllegalArgumentException, IOException {
  try (Table table = RESTServlet.getInstance().getTable(tableName)) {
    Get get = new Get(rowspec.getRow());
    if (rowspec.hasColumns()) {
      for (byte[] col : rowspec.getColumns()) {
        byte[][] split = CellUtil.parseColumn(col);
        if (split.length == 1) {
          get.addFamily(split[0]);
        } else if (split.length == 2) {
          get.addColumn(split[0], split[1]);
        } else {
          throw new IllegalArgumentException("Invalid column specifier.");
        }
      }
    }
    get.setTimeRange(rowspec.getStartTime(), rowspec.getEndTime());
    get.readVersions(rowspec.getMaxVersions());
    if (filter != null) {
      get.setFilter(filter);
    }
    get.setCacheBlocks(cacheBlocks);
    Result result = table.get(get);
    if (result != null && !result.isEmpty()) {
      valuesI = result.listCells().iterator();
    }
  } catch (DoNotRetryIOException e) {
    // Warn here because Stargate will return 404 in the case if multiple
    // column families were specified but one did not exist -- currently
    // HBase will fail the whole Get.
    // Specifying multiple columns in a URI should be uncommon usage but
    // help to avoid confusion by leaving a record of what happened here in
    // the log.
    LOG.warn(StringUtils.stringifyException(e));
    // Lets get the exception rethrown to get a more meaningful error message than 404
    if (e instanceof AccessDeniedException) {
      throw e;
    }
  }
}