use of org.apache.hadoop.hbase.client.BufferedMutator in project drill by apache.
the class TestTableGenerator method generateHBaseDataset3.
public static void generateHBaseDataset3(Connection conn, Admin admin, TableName tableName, int numberRegions) throws Exception {
if (admin.tableExists(tableName)) {
admin.disableTable(tableName);
admin.deleteTable(tableName);
}
HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(new HColumnDescriptor(FAMILY_F));
if (numberRegions > 1) {
admin.createTable(desc, Arrays.copyOfRange(SPLIT_KEYS, 0, numberRegions - 1));
} else {
admin.createTable(desc);
}
BufferedMutator table = conn.getBufferedMutator(tableName);
for (int i = 0; i <= 100; ++i) {
Put p = new Put((String.format("%03d", i)).getBytes());
p.addColumn(FAMILY_F, COLUMN_C, String.format("value %03d", i).getBytes());
table.mutate(p);
}
for (int i = 0; i <= 1000; ++i) {
Put p = new Put((String.format("%04d", i)).getBytes());
p.addColumn(FAMILY_F, COLUMN_C, String.format("value %04d", i).getBytes());
table.mutate(p);
}
Put p = new Put("%_AS_PREFIX_ROW1".getBytes());
p.addColumn(FAMILY_F, COLUMN_C, "dummy".getBytes());
table.mutate(p);
p = new Put("%_AS_PREFIX_ROW2".getBytes());
p.addColumn(FAMILY_F, COLUMN_C, "dummy".getBytes());
table.mutate(p);
table.close();
admin.flush(tableName);
}
use of org.apache.hadoop.hbase.client.BufferedMutator in project drill by apache.
the class TestTableGenerator method generateHBaseDatasetCompositeKeyInt.
public static void generateHBaseDatasetCompositeKeyInt(Connection conn, Admin admin, TableName tableName, int numberRegions) throws Exception {
if (admin.tableExists(tableName)) {
admin.disableTable(tableName);
admin.deleteTable(tableName);
}
HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(new HColumnDescriptor(FAMILY_F));
if (numberRegions > 1) {
admin.createTable(desc, Arrays.copyOfRange(SPLIT_KEYS, 0, numberRegions - 1));
} else {
admin.createTable(desc);
}
BufferedMutator table = conn.getBufferedMutator(tableName);
int startVal = 0;
int stopVal = 1000;
int interval = 47;
long counter = 0;
for (int i = startVal; i < stopVal; i += interval, counter++) {
byte[] rowKey = ByteBuffer.allocate(12).putInt(i).array();
for (int j = 0; j < 8; ++j) {
rowKey[4 + j] = (byte) (counter >> (56 - (j * 8)));
}
Put p = new Put(rowKey);
p.addColumn(FAMILY_F, COLUMN_C, "dummy".getBytes());
table.mutate(p);
}
table.close();
}
use of org.apache.hadoop.hbase.client.BufferedMutator in project drill by apache.
the class TestTableGenerator method generateHBaseDatasetBigIntOBDesc.
public static void generateHBaseDatasetBigIntOBDesc(Connection conn, Admin admin, TableName tableName, int numberRegions) throws Exception {
if (admin.tableExists(tableName)) {
admin.disableTable(tableName);
admin.deleteTable(tableName);
}
HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(new HColumnDescriptor(FAMILY_F));
if (numberRegions > 1) {
admin.createTable(desc, Arrays.copyOfRange(SPLIT_KEYS, 0, numberRegions - 1));
} else {
admin.createTable(desc);
}
BufferedMutator table = conn.getBufferedMutator(tableName);
long startTime = (long) 1438034423 * 1000;
for (long i = startTime; i <= startTime + 100; i++) {
byte[] bytes = new byte[9];
PositionedByteRange br = new SimplePositionedMutableByteRange(bytes, 0, 9);
OrderedBytes.encodeInt64(br, i, Order.DESCENDING);
Put p = new Put(bytes);
p.addColumn(FAMILY_F, COLUMN_C, String.format("value %d", i).getBytes());
table.mutate(p);
}
table.close();
admin.flush(tableName);
}
use of org.apache.hadoop.hbase.client.BufferedMutator in project gora by apache.
the class HBaseTableConnection method flushCommits.
public void flushCommits() throws IOException {
BufferedMutator bufMutator = connection.getBufferedMutator(this.tableName);
for (ConcurrentLinkedQueue<Mutation> buffer : bPool) {
while (!buffer.isEmpty()) {
Mutation m = buffer.poll();
bufMutator.mutate(m);
}
}
bufMutator.flush();
bufMutator.close();
}
use of org.apache.hadoop.hbase.client.BufferedMutator in project hbase by apache.
the class HBaseTestingUtility method createRandomTable.
/** Creates a random table with the given parameters */
public Table createRandomTable(TableName tableName, final Collection<String> families, final int maxVersions, final int numColsPerRow, final int numFlushes, final int numRegions, final int numRowsPerFlush) throws IOException, InterruptedException {
LOG.info("\n\nCreating random table " + tableName + " with " + numRegions + " regions, " + numFlushes + " storefiles per region, " + numRowsPerFlush + " rows per flush, maxVersions=" + maxVersions + "\n");
final Random rand = new Random(tableName.hashCode() * 17L + 12938197137L);
final int numCF = families.size();
final byte[][] cfBytes = new byte[numCF][];
{
int cfIndex = 0;
for (String cf : families) {
cfBytes[cfIndex++] = Bytes.toBytes(cf);
}
}
final int actualStartKey = 0;
final int actualEndKey = Integer.MAX_VALUE;
final int keysPerRegion = (actualEndKey - actualStartKey) / numRegions;
final int splitStartKey = actualStartKey + keysPerRegion;
final int splitEndKey = actualEndKey - keysPerRegion;
final String keyFormat = "%08x";
final Table table = createTable(tableName, cfBytes, maxVersions, Bytes.toBytes(String.format(keyFormat, splitStartKey)), Bytes.toBytes(String.format(keyFormat, splitEndKey)), numRegions);
if (hbaseCluster != null) {
getMiniHBaseCluster().flushcache(TableName.META_TABLE_NAME);
}
BufferedMutator mutator = getConnection().getBufferedMutator(tableName);
for (int iFlush = 0; iFlush < numFlushes; ++iFlush) {
for (int iRow = 0; iRow < numRowsPerFlush; ++iRow) {
final byte[] row = Bytes.toBytes(String.format(keyFormat, actualStartKey + rand.nextInt(actualEndKey - actualStartKey)));
Put put = new Put(row);
Delete del = new Delete(row);
for (int iCol = 0; iCol < numColsPerRow; ++iCol) {
final byte[] cf = cfBytes[rand.nextInt(numCF)];
final long ts = rand.nextInt();
final byte[] qual = Bytes.toBytes("col" + iCol);
if (rand.nextBoolean()) {
final byte[] value = Bytes.toBytes("value_for_row_" + iRow + "_cf_" + Bytes.toStringBinary(cf) + "_col_" + iCol + "_ts_" + ts + "_random_" + rand.nextLong());
put.addColumn(cf, qual, ts, value);
} else if (rand.nextDouble() < 0.8) {
del.addColumn(cf, qual, ts);
} else {
del.addColumns(cf, qual, ts);
}
}
if (!put.isEmpty()) {
mutator.mutate(put);
}
if (!del.isEmpty()) {
mutator.mutate(del);
}
}
LOG.info("Initiating flush #" + iFlush + " for table " + tableName);
mutator.flush();
if (hbaseCluster != null) {
getMiniHBaseCluster().flushcache(table.getName());
}
}
mutator.close();
return table;
}
Aggregations