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

The following examples show how to use org.apache.hadoop.hbase.util.Bytes#indexOf() . 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: TupleProjector.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * Iterate over the list of cells and populate dynamic columns
 * @param result list of cells
 * @param dynCols Populated list of PColumns corresponding to dynamic columns
 * @param dynColCellQualifiers Populated set of <column family, column qualifier> pairs
 *                             for the cells in the list, which correspond to dynamic columns
 * @throws InvalidProtocolBufferException Thrown if there is an error parsing byte[] to protobuf
 */
private static void populateDynColsFromResult(List<Cell> result, List<PColumn> dynCols,
        Set<Pair<ByteBuffer, ByteBuffer>> dynColCellQualifiers)
throws InvalidProtocolBufferException {
    for (Cell c : result) {
        byte[] qual = CellUtil.cloneQualifier(c);
        byte[] fam = CellUtil.cloneFamily(c);
        int index = Bytes.indexOf(qual, DYN_COLS_METADATA_CELL_QUALIFIER);

        // Contains dynamic column metadata, so add it to the list of dynamic columns
        if (index != -1) {
            byte[] dynColMetaDataProto = CellUtil.cloneValue(c);
            dynCols.add(PColumnImpl.createFromProto(
                    PTableProtos.PColumn.parseFrom(dynColMetaDataProto)));
            // Add the <fam, qualifier> pair for the actual dynamic column. The column qualifier
            // of the dynamic column is got by parsing out the known bytes from the shadow cell
            // containing the metadata for that column i.e.
            // DYN_COLS_METADATA_CELL_QUALIFIER<actual column qualifier>
            byte[] dynColQual = Arrays.copyOfRange(qual,
                    index + DYN_COLS_METADATA_CELL_QUALIFIER.length, qual.length);
            dynColCellQualifiers.add(
                    new Pair<>(ByteBuffer.wrap(fam), ByteBuffer.wrap(dynColQual)));
        }
    }
}
 
Example 2
Source File: MultiTableHFileOutputFormat.java    From hbase with Apache License 2.0 5 votes vote down vote up
final private static int validateCompositeKey(byte[] keyBytes) {

    int separatorIdx = Bytes.indexOf(keyBytes, tableSeparator);

    // Either the separator was not found or a tablename wasn't present or a key wasn't present
    if (separatorIdx == -1) {
      throw new IllegalArgumentException("Invalid format for composite key [" + Bytes
              .toStringBinary(keyBytes) + "]. Cannot extract tablename and suffix from key");
    }
    return separatorIdx;
  }
 
Example 3
Source File: IntegrationTestWithCellVisibilityLoadAndVerify.java    From hbase with Apache License 2.0 5 votes vote down vote up
private Counter getCounter(byte[] row) {
  Counter c = null;
  if (Bytes.indexOf(row, Bytes.toBytes(VISIBILITY_EXPS[0])) != -1) {
    c = rowsExp1;
  } else if (Bytes.indexOf(row, Bytes.toBytes(VISIBILITY_EXPS[1])) != -1) {
    c = rowsExp2;
  } else if (Bytes.indexOf(row, Bytes.toBytes(VISIBILITY_EXPS[2])) != -1) {
    c = rowsExp3;
  } else if (Bytes.indexOf(row, Bytes.toBytes(VISIBILITY_EXPS[3])) != -1) {
    c = rowsExp4;
  }
  return c;
}
 
Example 4
Source File: IndexToolIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static void verifyIndexTableRowKey(byte[] rowKey, String indexTableFullName) {
    // The row key for the output table : timestamp | index table name | data row key
    // The row key for the result table : timestamp | index table name | datable table region name |
    //                                    scan start row | scan stop row

    // This method verifies the common prefix, i.e., "timestamp | index table name | ", since the rest of the
    // fields may include the separator key
    int offset = Bytes.indexOf(rowKey, IndexVerificationResultRepository.ROW_KEY_SEPARATOR_BYTE);
    offset++;
    byte[] indexTableFullNameBytes = Bytes.toBytes(indexTableFullName);
    assertEquals(Bytes.compareTo(rowKey, offset, indexTableFullNameBytes.length, indexTableFullNameBytes, 0,
            indexTableFullNameBytes.length), 0);
    assertEquals(rowKey[offset + indexTableFullNameBytes.length],
        IndexVerificationResultRepository.ROW_KEY_SEPARATOR_BYTE[0]);
}