Java Code Examples for org.apache.hadoop.hbase.util.Bytes#copy()

The following examples show how to use org.apache.hadoop.hbase.util.Bytes#copy() . 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: hbase   File: Put.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create a Put operation for an immutable row key, using a given timestamp.
 *
 * @param row row key
 * @param ts timestamp
 * @param rowIsImmutable whether the input row is immutable.
 *                       Set to true if the caller can guarantee that
 *                       the row will not be changed for the Put duration.
 */
public Put(byte[] row, long ts, boolean rowIsImmutable) {
  // Check and set timestamp
  if (ts < 0) {
    throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + ts);
  }
  this.ts = ts;

  // Deal with row according to rowIsImmutable
  checkRow(row);
  if (rowIsImmutable) {  // Row is immutable
    this.row = row;  // Do not make a local copy, but point to the provided byte array directly
  } else {  // Row is not immutable
    this.row = Bytes.copy(row, 0, row.length);  // Make a local copy
  }
}
 
Example 2
@Override
public boolean overlapsRange(byte[] start,int startOff,int startLen,byte[] stop,int stopOff,int stopLen){
    byte[] s;
    byte[] e;
    if(startOff==0 && startLen==start.length)
        s=start;
    else s=Bytes.copy(start,startOff,startLen);

    if(stopOff==0 && stopLen==stop.length)
        e=stop;
    else e=Bytes.copy(stop,stopOff,stopLen);

    return region.getRegionInfo().containsRange(s,e);
}
 
Example 3
Source Project: hbase   File: RowMutations.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create an atomic mutation for the specified row.
 * @param row row key
 * @param initialCapacity the initial capacity of the RowMutations
 */
public RowMutations(byte [] row, int initialCapacity) {
  this.row = Bytes.copy(Mutation.checkRow(row));
  if (initialCapacity <= 0) {
    this.mutations = new ArrayList<>();
  } else {
    this.mutations = new ArrayList<>(initialCapacity);
  }
}
 
Example 4
/**
 * Get the appropriate bar for the value, extending existing bar bounds to accommodate if necessary
 * @param value value to add
 * @return the bar for the value
 */
@VisibleForTesting
Bar getBar(byte[] value) {
    Bar searchKey = new Bar(value, value);
    int searchIdx = Collections.binarySearch(this.bars, searchKey);
    if (searchIdx < 0) {
        // copy value so later changes by caller don't affect histogram results
        byte[] newBound = Bytes.copy(value);
        if (this.bars.size() == 0) {
            Bar firstBar = new Bar(newBound, newBound);
            bars.add(firstBar);
            return firstBar;
        }
        int expectedIndex = Math.abs(searchIdx + 1); // jdk binary search index
        if (expectedIndex == bars.size()) { // no bars >= value, need to extend rightBound of last bar
            Bar lastBar = bars.get(expectedIndex - 1);
            lastBar.setRightBoundExclusive(newBound); // actually inclusive for last bar
            return lastBar;
        } else { // extend leftBound of next greatest bar
            Bar nextBar = bars.get(expectedIndex);
            nextBar.setLeftBoundInclusive(newBound);
            return nextBar;
        }
    } else {
        return bars.get(searchIdx);
    }
}
 
Example 5
Source Project: phoenix-tephra   File: DataJanitorState.java    License: Apache License 2.0 5 votes vote down vote up
private Map.Entry<Long, byte[]> getTimeRegion(byte[] key) {
  int offset = REGION_TIME_KEY_PREFIX.length;
  long time = getInvertedTime(Bytes.toLong(key, offset));
  offset += Bytes.SIZEOF_LONG;
  byte[] regionName = Bytes.copy(key, offset, key.length - offset);
  return Maps.immutableEntry(time, regionName);
}
 
Example 6
Source Project: examples   File: DocumentInterceptor.java    License: Apache License 2.0 5 votes vote down vote up
protected Document cellToAvro(Cell cell, Document reuse) throws IOException {
  byte[] value =
      Bytes.copy(cell.getValueArray(), cell.getValueOffset(),
        cell.getValueLength());
  decoder = DecoderFactory.get().binaryDecoder(value, decoder);
  reuse = reader.read(reuse, decoder);
  return reuse;
}
 
Example 7
Source Project: phoenix-tephra   File: DataJanitorState.java    License: Apache License 2.0 5 votes vote down vote up
private Map.Entry<Long, byte[]> getTimeRegion(byte[] key) {
  int offset = REGION_TIME_KEY_PREFIX.length;
  long time = getInvertedTime(Bytes.toLong(key, offset));
  offset += Bytes.SIZEOF_LONG;
  byte[] regionName = Bytes.copy(key, offset, key.length - offset);
  return Maps.immutableEntry(time, regionName);
}
 
Example 8
Source Project: hbase   File: Put.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * We make a copy of the passed in row key to keep local.
 * @param rowArray
 * @param rowOffset
 * @param rowLength
 * @param ts
 */
public Put(byte [] rowArray, int rowOffset, int rowLength, long ts) {
  checkRow(rowArray, rowOffset, rowLength);
  this.row = Bytes.copy(rowArray, rowOffset, rowLength);
  this.ts = ts;
  if (ts < 0) {
    throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + ts);
  }
}
 
Example 9
Source Project: hbase   File: ImmutableScan.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public byte[][] getFamilies() {
  final byte[][] families = this.delegateScan.getFamilies();
  byte[][] cloneFamilies = new byte[families.length][];
  for (int i = 0; i < families.length; i++) {
    cloneFamilies[i] = Bytes.copy(families[i]);
  }
  return cloneFamilies;
}
 
Example 10
protected static byte[] getSuffix(byte[] keyBytes) {
  int separatorIdx = validateCompositeKey(keyBytes);
  return Bytes.copy(keyBytes, separatorIdx+1, keyBytes.length - separatorIdx - 1);
}
 
Example 11
protected static byte[] getTableName(byte[] keyBytes) {
  int separatorIdx = validateCompositeKey(keyBytes);
  return Bytes.copy(keyBytes, 0, separatorIdx);
}
 
Example 12
Source Project: phoenix-tephra   File: DataJanitorState.java    License: Apache License 2.0 4 votes vote down vote up
private byte[] getEmptyRegionFromKey(byte[] key) {
  int prefixLen = EMPTY_REGION_TIME_KEY_PREFIX.length + Bytes.SIZEOF_LONG;
  return Bytes.copy(key, prefixLen, key.length - prefixLen);
}
 
Example 13
public void addFamilyDelete(Cell delete) {
  this.familyDeleteTs = delete.getTimestamp();
  this.rowKey = Bytes.copy(delete.getRowArray(), delete.getRowOffset(), delete.getRowLength());
}
 
Example 14
public void addFamilyDelete(Cell delete) {
  this.familyDeleteTs = delete.getTimestamp();
  this.rowKey = Bytes.copy(delete.getRowArray(), delete.getRowOffset(), delete.getRowLength());
}
 
Example 15
@Override
public byte[] getName() {
  return Bytes.copy(name);
}
 
Example 16
public void addFamilyDelete(Cell delete) {
  this.familyDeleteTs = delete.getTimestamp();
  this.rowKey = Bytes.copy(delete.getRowArray(), delete.getRowOffset(), delete.getRowLength());
}
 
Example 17
Source Project: phoenix-tephra   File: DataJanitorState.java    License: Apache License 2.0 4 votes vote down vote up
private byte[] getRegionFromKey(byte[] regionKey) {
  int prefixLen = REGION_KEY_PREFIX.length;
  return Bytes.copy(regionKey, prefixLen, regionKey.length - prefixLen);
}
 
Example 18
Source Project: phoenix-tephra   File: DataJanitorState.java    License: Apache License 2.0 4 votes vote down vote up
private byte[] getEmptyRegionFromKey(byte[] key) {
  int prefixLen = EMPTY_REGION_TIME_KEY_PREFIX.length + Bytes.SIZEOF_LONG;
  return Bytes.copy(key, prefixLen, key.length - prefixLen);
}
 
Example 19
Source Project: phoenix-tephra   File: DataJanitorState.java    License: Apache License 2.0 4 votes vote down vote up
private byte[] getRegionFromKey(byte[] regionKey) {
  int prefixLen = REGION_KEY_PREFIX.length;
  return Bytes.copy(regionKey, prefixLen, regionKey.length - prefixLen);
}
 
Example 20
Source Project: hbase   File: Increment.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Create a Increment operation for the specified row.
 * <p>
 * At least one column must be incremented.
 * @param row row key (we will make a copy of this).
 */
public Increment(final byte [] row, final int offset, final int length) {
  checkRow(row, offset, length);
  this.row = Bytes.copy(row, offset, length);
}