本文整理汇总了Java中org.apache.hadoop.hbase.index.util.ByteArrayBuilder.allocate方法的典型用法代码示例。如果您正苦于以下问题:Java ByteArrayBuilder.allocate方法的具体用法?Java ByteArrayBuilder.allocate怎么用?Java ByteArrayBuilder.allocate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.hbase.index.util.ByteArrayBuilder
的用法示例。
在下文中一共展示了ByteArrayBuilder.allocate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addIndexForTable
import org.apache.hadoop.hbase.index.util.ByteArrayBuilder; //导入方法依赖的package包/类
/**
* @param tableName on which index applying
* @param indexList list of table
*/
public void addIndexForTable(String tableName, List<IndexSpecification> indexList) {
this.tableVsIndices.put(tableName, indexList);
// TODO the inner map needs to be thread safe when we support dynamic index add/remove
Map<byte[], IndexSpecification> indexMap =
new TreeMap<byte[], IndexSpecification>(Bytes.BYTES_COMPARATOR);
for (IndexSpecification index : indexList) {
ByteArrayBuilder keyBuilder = ByteArrayBuilder.allocate(IndexUtils.getMaxIndexNameLength());
keyBuilder.put(Bytes.toBytes(index.getName()));
indexMap.put(keyBuilder.array(), index);
}
this.tableIndexMap.put(tableName, indexMap);
}
示例2: createCommonKeyForIndex
import org.apache.hadoop.hbase.index.util.ByteArrayBuilder; //导入方法依赖的package包/类
private byte[] createCommonKeyForIndex(byte[] regionStartKey, byte[] indexName) {
// Format for index table rowkey [Startkey for the index region] + [one 0 byte]+
// [Index name] + [Padding for the max index name] + ....
int commonKeyLength = regionStartKey.length + 1 + IndexUtils.getMaxIndexNameLength();
ByteArrayBuilder builder = ByteArrayBuilder.allocate(commonKeyLength);
// Adding the startkey for the index region and single 0 Byte.
builder.put(regionStartKey);
builder.position(builder.position() + 1);
// Adding the index name and the padding needed
builder.put(indexName);
// No need to add the padding bytes specifically. In the array all the bytes will be 0s.
return builder.array();
}
示例3: formIndexNameFromKV
import org.apache.hadoop.hbase.index.util.ByteArrayBuilder; //导入方法依赖的package包/类
private byte[] formIndexNameFromKV(KeyValue kv) {
byte[] rowKey = kv.getRow();
// First two bytes are going to be the
ByteArrayBuilder keyBuilder = ByteArrayBuilder.allocate(rowKey.length);
// Start from 2nd offset because the first 2 bytes corresponds to the rowkeylength
keyBuilder.put(rowKey, 0, rowKey.length);
String replacedKey = Bytes.toString(keyBuilder.array());
String emptyByte = Bytes.toString(new byte[1]);
int indexOf = replacedKey.indexOf(emptyByte);
return keyBuilder.array(indexOf + 1, IndexUtils.getMaxIndexNameLength());
}
示例4: addIndexForTable
import org.apache.hadoop.hbase.index.util.ByteArrayBuilder; //导入方法依赖的package包/类
/**
* @param table name on which index applying
* @param IndexSpecification list of table
*/
public void addIndexForTable(String tableName, List<IndexSpecification> indexList) {
this.tableVsIndices.put(tableName, indexList);
// TODO the inner map needs to be thread safe when we support dynamic index add/remove
Map<byte[], IndexSpecification> indexMap =
new TreeMap<byte[], IndexSpecification>(Bytes.BYTES_COMPARATOR);
for (IndexSpecification index : indexList) {
ByteArrayBuilder keyBuilder = ByteArrayBuilder.allocate(IndexUtils.getMaxIndexNameLength());
keyBuilder.put(Bytes.toBytes(index.getName()));
indexMap.put(keyBuilder.array(), index);
}
this.tableIndexMap.put(tableName, indexMap);
}
示例5: formIndexNameFromKV
import org.apache.hadoop.hbase.index.util.ByteArrayBuilder; //导入方法依赖的package包/类
private byte[] formIndexNameFromKV(KeyValue kv) {
byte[] rowKey = kv.getRow();
// First two bytes are going to be the
ByteArrayBuilder keyBuilder = ByteArrayBuilder.allocate(rowKey.length);
// Start from 2nd offset because the first 2 bytes corresponds to the rowkeylength
keyBuilder.put(rowKey, 0, rowKey.length);
int indexOf = com.google.common.primitives.Bytes.indexOf(keyBuilder.array(), new byte[1]);
return keyBuilder.array(indexOf + 1, IndexUtils.getMaxIndexNameLength());
}
示例6: genSomeKeys
import org.apache.hadoop.hbase.index.util.ByteArrayBuilder; //导入方法依赖的package包/类
private List<KeyValue> genSomeKeys(String userTableName) throws Exception {
List<KeyValue> ret = new ArrayList<KeyValue>(4);
HTableDescriptor ihtd = new HTableDescriptor(TableName.valueOf(userTableName));
HColumnDescriptor hcd1 = new HColumnDescriptor("column1");
HColumnDescriptor hcd2 = new HColumnDescriptor("column2");
IndexSpecification iSpec1 = new IndexSpecification("Index");
iSpec1.addIndexColumn(hcd1, "q", ValueType.String, 10);
iSpec1.addIndexColumn(hcd2, "q", ValueType.String, 10);
ihtd.addFamily(hcd1);
ihtd.addFamily(hcd2);
TableIndices indices = new TableIndices();
indices.addIndex(iSpec1);
ihtd.setValue(Constants.INDEX_SPEC_KEY, indices.toByteArray());
admin.createTable(ihtd);
ByteArrayBuilder indexColVal = ByteArrayBuilder.allocate(4);
indexColVal.put(Bytes.toBytes((short) 3));
indexColVal.put(Bytes.toBytes((short) 32));
Put p1 = generatePuts("006".getBytes(), "05".getBytes());
Put p2 = generatePuts("003".getBytes(), "06".getBytes());
Put p3 = generatePuts("004".getBytes(), "06".getBytes());
Put p4 = generatePuts("007".getBytes(), "06".getBytes());
byte[] seekToPut =
new byte[3 + 1 + IndexUtils.getMaxIndexNameLength() + 10 + "006".getBytes().length];
System.arraycopy(p1.getRow(), 0, seekToPut, 0, p1.getRow().length);
byte[] seekToRow = "007".getBytes();
System.arraycopy(seekToRow, 0, seekToPut, p1.getRow().length - 3, seekToRow.length);
System.arraycopy("005".getBytes(), 0, seekToPut, 0, 3);
setSeekToRowKey(seekToPut, indexColVal);
byte[] expectedPut =
new byte[3 + 1 + IndexUtils.getMaxIndexNameLength() + 10 + "006".getBytes().length];
System.arraycopy(p4.getRow(), 0, expectedPut, 0, p4.getRow().length);
// Copy first 3 bytes to splitKey since getKeyValue will replace the start key with splitKey.
// Just for assertion this is been added
System.arraycopy("005".getBytes(), 0, expectedPut, 0, 3);
setExpected(expectedPut);
KeyValue kv =
new KeyValue(p1.getRow(), Constants.IDX_COL_FAMILY, Constants.IDX_COL_QUAL, 0,
indexColVal.array());
ret.add(kv);
KeyValue kv1 =
new KeyValue(p2.getRow(), Constants.IDX_COL_FAMILY, Constants.IDX_COL_QUAL, 0,
indexColVal.array());
ret.add(kv1);
KeyValue kv2 =
new KeyValue(p3.getRow(), Constants.IDX_COL_FAMILY, Constants.IDX_COL_QUAL, 0,
indexColVal.array());
ret.add(kv2);
KeyValue kv3 =
new KeyValue(p4.getRow(), Constants.IDX_COL_FAMILY, Constants.IDX_COL_QUAL, 0,
indexColVal.array());
ret.add(kv3);
return ret;
}
示例7: genSomeKeys
import org.apache.hadoop.hbase.index.util.ByteArrayBuilder; //导入方法依赖的package包/类
private List<KeyValue> genSomeKeys(String userTableName) throws Exception {
List<KeyValue> ret = new ArrayList<KeyValue>(4);
HBaseAdmin admin = UTIL.getHBaseAdmin();
ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(UTIL);
IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(userTableName);
HColumnDescriptor hcd1 = new HColumnDescriptor("column1");
HColumnDescriptor hcd2 = new HColumnDescriptor("column2");
IndexSpecification iSpec1 = new IndexSpecification("Index");
iSpec1.addIndexColumn(hcd1, "q", ValueType.String, 10);
iSpec1.addIndexColumn(hcd2, "q", ValueType.String, 10);
ihtd.addFamily(hcd1);
ihtd.addFamily(hcd2);
ihtd.addIndex(iSpec1);
admin.createTable(ihtd);
ZKAssign.blockUntilNoRIT(zkw);
ByteArrayBuilder indexColVal = ByteArrayBuilder.allocate(4);
indexColVal.put(Bytes.toBytes((short) 3));
indexColVal.put(Bytes.toBytes((short) 32));
Put p1 = generatePuts("006".getBytes(), "05".getBytes());
Put p2 = generatePuts("003".getBytes(), "06".getBytes());
Put p3 = generatePuts("004".getBytes(), "06".getBytes());
Put p4 = generatePuts("007".getBytes(), "06".getBytes());
byte[] seekToPut =
new byte[3 + 1 + IndexUtils.getMaxIndexNameLength() + 10 + "006".getBytes().length];
System.arraycopy(p1.getRow(), 0, seekToPut, 0, p1.getRow().length);
byte[] seekToRow = "007".getBytes();
System.arraycopy(seekToRow, 0, seekToPut, p1.getRow().length - 3, seekToRow.length);
System.arraycopy("005".getBytes(), 0, seekToPut, 0, 3);
setSeekToRowKey(seekToPut, indexColVal);
byte[] expectedPut =
new byte[3 + 1 + IndexUtils.getMaxIndexNameLength() + 10 + "006".getBytes().length];
System.arraycopy(p4.getRow(), 0, expectedPut, 0, p4.getRow().length);
// Copy first 3 bytes to splitKey since getKeyValue will replace the start key with splitKey.
// Just for assertion this is been added
System.arraycopy("005".getBytes(), 0, expectedPut, 0, 3);
setExpected(expectedPut);
KeyValue kv =
new KeyValue(p1.getRow(), Constants.IDX_COL_FAMILY, Constants.IDX_COL_QUAL, 0,
indexColVal.array());
ret.add(kv);
KeyValue kv1 =
new KeyValue(p2.getRow(), Constants.IDX_COL_FAMILY, Constants.IDX_COL_QUAL, 0,
indexColVal.array());
ret.add(kv1);
KeyValue kv2 =
new KeyValue(p3.getRow(), Constants.IDX_COL_FAMILY, Constants.IDX_COL_QUAL, 0,
indexColVal.array());
ret.add(kv2);
KeyValue kv3 =
new KeyValue(p4.getRow(), Constants.IDX_COL_FAMILY, Constants.IDX_COL_QUAL, 0,
indexColVal.array());
ret.add(kv3);
return ret;
}