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

The following are Jave code examples for showing how to use add() of the org.apache.hadoop.hbase.util.Bytes class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ditb   File: ClientScanner.java   View Source Code Vote up 6 votes
/**
 * Create the closest row before the specified row
 * @param row
 * @return a new byte array which is the closest front row of the specified one
 */
protected static byte[] createClosestRowBefore(byte[] row) {
  if (row == null) {
    throw new IllegalArgumentException("The passed row is empty");
  }
  if (Bytes.equals(row, HConstants.EMPTY_BYTE_ARRAY)) {
    return MAX_BYTE_ARRAY;
  }
  if (row[row.length - 1] == 0) {
    return Arrays.copyOf(row, row.length - 1);
  } else {
    byte[] closestFrontRow = Arrays.copyOf(row, row.length);
    closestFrontRow[row.length - 1] = (byte) ((closestFrontRow[row.length - 1] & 0xff) - 1);
    closestFrontRow = Bytes.add(closestFrontRow, MAX_BYTE_ARRAY);
    return closestFrontRow;
  }
}
 
Example 2
Project: easyhbase   File: RowKeyDistributorByOneBytePrefix.java   View Source Code Vote up 5 votes
@Override
public byte[] getDistributedKey(byte[] originalKey) {
  byte[] key = Bytes.add(PREFIXES[nextPrefix++], originalKey);
  nextPrefix = (byte) (nextPrefix % maxPrefix);

  return key;
}
 
Example 3
Project: easyhbase   File: RowKeyDistributorByHashPrefix.java   View Source Code Vote up 5 votes
@Override
public byte[][] getAllDistributedKeys(byte[] originalKey) {
  byte[][] allPrefixes = hasher.getAllPossiblePrefixes();
  byte[][] keys = new byte[allPrefixes.length][];
  for (int i = 0; i < allPrefixes.length; i++) {
    keys[i] = Bytes.add(allPrefixes[i], originalKey);
  }

  return keys;
}
 
Example 4
Project: easyhbase   File: OneByteTest.java   View Source Code Vote up 5 votes
@Test
public void computeOneByteTest() {
    byte nextPrefix = 0;
    byte maxPrefix = 64;
    byte[] originalKey = new byte[]{0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    byte[] key = Bytes.add(PREFIXES[nextPrefix++], originalKey);
    nextPrefix = (byte) (nextPrefix % maxPrefix);

    System.out.println(Bytes.toStringBinary(key));
}
 
Example 5
Project: ditb   File: TestBatchCoprocessorEndpoint.java   View Source Code Vote up 5 votes
private static byte[][] makeN(byte[] base, int n) {
  byte[][] ret = new byte[n][];
  for (int i = 0; i < n; i++) {
    ret[i] = Bytes.add(base, Bytes.toBytes(String.format("%02d", i)));
  }
  return ret;
}
 
Example 6
Project: ditb   File: ExampleAWorkload.java   View Source Code Vote up 5 votes
@Override public byte[][] getSplits() {
  if (nbRegion <= 1) return null;
  byte[][] splits = new byte[nbRegion][];
  byte[] right = Bytes.toBytes(0);
  for (int i = 0; i < nbRegion; i++) {
    splits[i] = Bytes.add(Bytes.toBytes(i), right);
  }
  return splits;
}
 
Example 7
Project: ditb   File: ServerName.java   View Source Code Vote up 5 votes
/**
 * @return {@link #getServerName()} as bytes with a short-sized prefix with
 * the ServerName#VERSION of this class.
 */
public synchronized byte [] getVersionedBytes() {
  if (this.bytes == null) {
    this.bytes = Bytes.add(VERSION_BYTES, Bytes.toBytes(getServerName()));
  }
  return this.bytes;
}
 
Example 8
Project: ditb   File: TestCoprocessorEndpoint.java   View Source Code Vote up 5 votes
private static byte[][] makeN(byte[] base, int n) {
  byte[][] ret = new byte[n][];
  for (int i = 0; i < n; i++) {
    ret[i] = Bytes.add(base, Bytes.toBytes(String.format("%02d", i)));
  }
  return ret;
}
 
Example 9
Project: ditb   File: SimpleIndexKeyGenerator.java   View Source Code Vote up 5 votes
@Override public byte[] createIndexRowKey(byte[] rowKey, byte[] value) {
  if (value == null || value.length == 0) {
    return null;
  }
  value = Bytes.add(value, IndexConstants.MIN_ROW_KEY);
  byte[] a = Bytes.toBytes(IndexConstants.LASTPART_ZERO
      .substring(0, IndexConstants.LASTPART_LENGTH - ("" + value.length).length())
      + value.length);
  return Bytes.add(value, rowKey, a);
}
 
Example 10
Project: ditb   File: ThriftServerRunner.java   View Source Code Vote up 5 votes
/**
 * Returns a list of all the column families for a given Table.
 *
 * @param table
 * @throws IOException
 */
byte[][] getAllColumns(Table table) throws IOException {
  HColumnDescriptor[] cds = table.getTableDescriptor().getColumnFamilies();
  byte[][] columns = new byte[cds.length][];
  for (int i = 0; i < cds.length; i++) {
    columns[i] = Bytes.add(cds[i].getName(),
        KeyValue.COLUMN_FAMILY_DELIM_ARRAY);
  }
  return columns;
}
 
Example 11
Project: ditb   File: IndexSpecification.java   View Source Code Vote up 5 votes
/**
 * Set column for this index.
 *
 * @param indexColumn
 */
public void setIndexColumn(byte[] indexColumn) {
  this.indexColumn = indexColumn;
  byte[][] fq = KeyValue.parseColumn(this.indexColumn);
  this.family = fq[0];
  this.qualifier = fq[1];
  this.indexId = Bytes.add(this.family, Bytes.toBytes("_"), this.qualifier);
}
 
Example 12
Project: ditb   File: StoreFile.java   View Source Code Vote up 5 votes
public Reader createLCIndexReader(ScanRange scanRange, HStore store) throws IOException {
  byte[] key = Bytes.add(scanRange.getFamily(), scanRange.getQualifier());
  Reader reader = lcIndexReaders.get(key);
  if (reader == null) reader = openLCIndexReader(scanRange.getQualifier(), store);
  if (reader == null) throw new IOException(
      "winter meet error here, did not add reader for " + ColumnInfo
          .transToString(scanRange.getFamily(), scanRange.getQualifier()));
  lcIndexReaders.put(key, reader);
  return reader;
}
 
Example 13
Project: ditb   File: TestAggregateProtocol.java   View Source Code Vote up 5 votes
/**
 * an infrastructure method to prepare rows for the testtable.
 * @param base
 * @param n
 * @return
 */
private static byte[][] makeN(byte[] base, int n) {
  byte[][] ret = new byte[n][];
  for (int i = 0; i < n; i++) {
    ret[i] = Bytes.add(base, Bytes.toBytes(i));
  }
  return ret;
}
 
Example 14
Project: easyhbase   File: RowKeyDistributorByHashPrefix.java   View Source Code Vote up 4 votes
@Override
public byte[] getDistributedKey(byte[] originalKey) {
  return Bytes.add(hasher.getHashPrefix(originalKey), originalKey);
}
 
Example 15
Project: ditb   File: QuotaTableUtil.java   View Source Code Vote up 4 votes
protected static byte[] getNamespaceRowKey(final String namespace) {
  return Bytes.add(QUOTA_NAMESPACE_ROW_KEY_PREFIX, Bytes.toBytes(namespace));
}
 
Example 16
Project: ditb   File: IndexUtils.java   View Source Code Vote up 4 votes
private static byte[] columnName(KeyValue kv) {
  return Bytes.add(kv.getFamily(), Bytes.toBytes(":"), kv.getQualifier());
}
 
Example 17
Project: ditb   File: QuotaTableUtil.java   View Source Code Vote up 4 votes
protected static byte[] getTableRowKey(final TableName table) {
  return Bytes.add(QUOTA_TABLE_ROW_KEY_PREFIX, table.getName());
}
 
Example 18
Project: ditb   File: ClientSmallScanner.java   View Source Code Vote up 4 votes
/**
 * Gets a scanner for following scan. Move to next region or continue from the
 * last result or start from the start row.
 * @param nbRows
 * @param done true if Server-side says we're done scanning.
 * @param currentRegionDone true if scan is over on current region
 * @return true if has next scanner
 * @throws IOException
 */
private boolean nextScanner(int nbRows, final boolean done,
    boolean currentRegionDone) throws IOException {
  // Where to start the next getter
  byte[] localStartKey;
  int cacheNum = nbRows;
  boolean regionChanged = true;
  // if we're at end of table, close and return false to stop iterating
  if (this.currentRegion != null && currentRegionDone) {
    byte[] endKey = this.currentRegion.getEndKey();
    if (endKey == null || Bytes.equals(endKey, HConstants.EMPTY_BYTE_ARRAY)
        || checkScanStopRow(endKey) || done) {
      close();
      if (LOG.isTraceEnabled()) {
        LOG.trace("Finished with small scan at " + this.currentRegion);
      }
      return false;
    }
    localStartKey = endKey;
    if (LOG.isTraceEnabled()) {
      LOG.trace("Finished with region " + this.currentRegion);
    }
  } else if (this.lastResult != null) {
    regionChanged = false;
    localStartKey = Bytes.add(lastResult.getRow(), new byte[1]);
  } else {
    localStartKey = this.scan.getStartRow();
  }

  if (LOG.isTraceEnabled()) {
    LOG.trace("Advancing internal small scanner to startKey at '"
        + Bytes.toStringBinary(localStartKey) + "'");
  }
  smallScanCallable = callableFactory.getCallable(getConnection(), getTable(), scan,
      getScanMetrics(), localStartKey, cacheNum, rpcControllerFactory, getPool(),
      getPrimaryOperationTimeout(), getRetries(), getScannerTimeout(), getConf(), caller);
  if (this.scanMetrics != null && regionChanged) {
    this.scanMetrics.countOfRegions.incrementAndGet();
  }
  return true;
}
 
Example 19
Project: ditb   File: IntegrationTestLoadAndVerify.java   View Source Code Vote up 4 votes
@Override
protected void map(NullWritable key, NullWritable value,
    Context context) throws IOException, InterruptedException {

  String suffix = "/" + shortTaskId;
  byte[] row = Bytes.add(new byte[8], Bytes.toBytes(suffix));

  int BLOCK_SIZE = (int)(recordsToWrite / 100);

  for (long i = 0; i < recordsToWrite;) {
    long blockStart = i;
    for (long idxInBlock = 0;
         idxInBlock < BLOCK_SIZE && i < recordsToWrite;
         idxInBlock++, i++) {

      long byteSwapped = swapLong(i);
      Bytes.putLong(row, 0, byteSwapped);

      Put p = new Put(row);
      p.add(TEST_FAMILY, TEST_QUALIFIER, HConstants.EMPTY_BYTE_ARRAY);
      if (blockStart > 0) {
        for (int j = 0; j < numBackReferencesPerRow; j++) {
          long referredRow = blockStart - BLOCK_SIZE + rand.nextInt(BLOCK_SIZE);
          Bytes.putLong(row, 0, swapLong(referredRow));
          p.add(TEST_FAMILY, row, HConstants.EMPTY_BYTE_ARRAY);
        }
        refsWritten.increment(1);
      }
      rowsWritten.increment(1);
      mutator.mutate(p);

      if (i % 100 == 0) {
        context.setStatus("Written " + i + "/" + recordsToWrite + " records");
        context.progress();
      }
    }
    // End of block, flush all of them before we start writing anything
    // pointing to these!
    mutator.flush();
  }
}
 
Example 20
Project: ditb   File: KeyValue.java   View Source Code Vote up 2 votes
/**
 * Makes a column in family:qualifier form from separate byte arrays.
 * <p>
 * Not recommended for usage as this is old-style API.
 * @param family
 * @param qualifier
 * @return family:qualifier
 */
public static byte [] makeColumn(byte [] family, byte [] qualifier) {
  return Bytes.add(family, COLUMN_FAMILY_DELIM_ARRAY, qualifier);
}