use of org.apache.hadoop.hbase.client.Get in project hbase by apache.
the class TestQuotaThrottle method doGets.
private long doGets(int maxOps, final Table... tables) throws Exception {
int count = 0;
try {
while (count < maxOps) {
Get get = new Get(Bytes.toBytes("row-" + count));
for (final Table table : tables) {
table.get(get);
}
count += tables.length;
}
} catch (ThrottlingException e) {
LOG.error("get failed after nRetries=" + count, e);
}
return count;
}
use of org.apache.hadoop.hbase.client.Get in project hbase by apache.
the class TestProtobufUtil method testGet.
/**
* Test basic Get conversions.
*
* @throws IOException
*/
@Test
public void testGet() throws IOException {
ClientProtos.Get.Builder getBuilder = ClientProtos.Get.newBuilder();
getBuilder.setRow(ByteString.copyFromUtf8("row"));
Column.Builder columnBuilder = Column.newBuilder();
columnBuilder.setFamily(ByteString.copyFromUtf8("f1"));
columnBuilder.addQualifier(ByteString.copyFromUtf8("c1"));
columnBuilder.addQualifier(ByteString.copyFromUtf8("c2"));
getBuilder.addColumn(columnBuilder.build());
columnBuilder.clear();
columnBuilder.setFamily(ByteString.copyFromUtf8("f2"));
getBuilder.addColumn(columnBuilder.build());
getBuilder.setLoadColumnFamiliesOnDemand(true);
ClientProtos.Get proto = getBuilder.build();
// default fields
assertEquals(1, proto.getMaxVersions());
assertEquals(true, proto.getCacheBlocks());
// set the default value for equal comparison
getBuilder = ClientProtos.Get.newBuilder(proto);
getBuilder.setMaxVersions(1);
getBuilder.setCacheBlocks(true);
Get get = ProtobufUtil.toGet(proto);
assertEquals(getBuilder.build(), ProtobufUtil.toGet(get));
}
use of org.apache.hadoop.hbase.client.Get in project hbase by apache.
the class TestJavaHBaseContext method testBulkPut.
@Test
public void testBulkPut() throws IOException {
List<String> list = new ArrayList<>(5);
list.add("1," + columnFamilyStr + ",a,1");
list.add("2," + columnFamilyStr + ",a,2");
list.add("3," + columnFamilyStr + ",a,3");
list.add("4," + columnFamilyStr + ",a,4");
list.add("5," + columnFamilyStr + ",a,5");
JavaRDD<String> rdd = jsc.parallelize(list);
Configuration conf = htu.getConfiguration();
JavaHBaseContext hbaseContext = new JavaHBaseContext(jsc, conf);
Connection conn = ConnectionFactory.createConnection(conf);
Table table = conn.getTable(TableName.valueOf(tableName));
try {
List<Delete> deletes = new ArrayList<>(5);
for (int i = 1; i < 6; i++) {
deletes.add(new Delete(Bytes.toBytes(Integer.toString(i))));
}
table.delete(deletes);
} finally {
table.close();
}
hbaseContext.bulkPut(rdd, TableName.valueOf(tableName), new PutFunction());
table = conn.getTable(TableName.valueOf(tableName));
try {
Result result1 = table.get(new Get(Bytes.toBytes("1")));
Assert.assertNotNull("Row 1 should had been deleted", result1.getRow());
Result result2 = table.get(new Get(Bytes.toBytes("2")));
Assert.assertNotNull("Row 2 should had been deleted", result2.getRow());
Result result3 = table.get(new Get(Bytes.toBytes("3")));
Assert.assertNotNull("Row 3 should had been deleted", result3.getRow());
Result result4 = table.get(new Get(Bytes.toBytes("4")));
Assert.assertNotNull("Row 4 should had been deleted", result4.getRow());
Result result5 = table.get(new Get(Bytes.toBytes("5")));
Assert.assertNotNull("Row 5 should had been deleted", result5.getRow());
} finally {
table.close();
conn.close();
}
}
use of org.apache.hadoop.hbase.client.Get in project hbase by apache.
the class TestJavaHBaseContext method testBulkDelete.
@Test
public void testBulkDelete() throws IOException {
List<byte[]> list = new ArrayList<>(3);
list.add(Bytes.toBytes("1"));
list.add(Bytes.toBytes("2"));
list.add(Bytes.toBytes("3"));
JavaRDD<byte[]> rdd = jsc.parallelize(list);
Configuration conf = htu.getConfiguration();
populateTableWithMockData(conf, TableName.valueOf(tableName));
JavaHBaseContext hbaseContext = new JavaHBaseContext(jsc, conf);
hbaseContext.bulkDelete(rdd, TableName.valueOf(tableName), new JavaHBaseBulkDeleteExample.DeleteFunction(), 2);
try (Connection conn = ConnectionFactory.createConnection(conf);
Table table = conn.getTable(TableName.valueOf(tableName))) {
Result result1 = table.get(new Get(Bytes.toBytes("1")));
Assert.assertNull("Row 1 should had been deleted", result1.getRow());
Result result2 = table.get(new Get(Bytes.toBytes("2")));
Assert.assertNull("Row 2 should had been deleted", result2.getRow());
Result result3 = table.get(new Get(Bytes.toBytes("3")));
Assert.assertNull("Row 3 should had been deleted", result3.getRow());
Result result4 = table.get(new Get(Bytes.toBytes("4")));
Assert.assertNotNull("Row 4 should had been deleted", result4.getRow());
Result result5 = table.get(new Get(Bytes.toBytes("5")));
Assert.assertNotNull("Row 5 should had been deleted", result5.getRow());
}
}
use of org.apache.hadoop.hbase.client.Get in project hbase by apache.
the class RegionAsTable method existsAll.
@Override
public boolean[] existsAll(List<Get> gets) throws IOException {
boolean[] results = new boolean[gets.size()];
int index = 0;
for (Get get : gets) {
results[index++] = exists(get);
}
return results;
}
Aggregations