Search in sources :

Example 21 with Get

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;
}
Also used : Table(org.apache.hadoop.hbase.client.Table) Get(org.apache.hadoop.hbase.client.Get)

Example 22 with Get

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));
}
Also used : Column(org.apache.hadoop.hbase.protobuf.generated.ClientProtos.Column) Get(org.apache.hadoop.hbase.client.Get) ClientProtos(org.apache.hadoop.hbase.protobuf.generated.ClientProtos) Test(org.junit.Test)

Example 23 with 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();
    }
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Table(org.apache.hadoop.hbase.client.Table) Configuration(org.apache.hadoop.conf.Configuration) Connection(org.apache.hadoop.hbase.client.Connection) Result(org.apache.hadoop.hbase.client.Result) Get(org.apache.hadoop.hbase.client.Get)

Example 24 with Get

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());
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) Configuration(org.apache.hadoop.conf.Configuration) JavaHBaseBulkDeleteExample(org.apache.hadoop.hbase.spark.example.hbasecontext.JavaHBaseBulkDeleteExample) Get(org.apache.hadoop.hbase.client.Get) Connection(org.apache.hadoop.hbase.client.Connection) Result(org.apache.hadoop.hbase.client.Result)

Example 25 with Get

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;
}
Also used : Get(org.apache.hadoop.hbase.client.Get)

Aggregations

Get (org.apache.hadoop.hbase.client.Get)629 Result (org.apache.hadoop.hbase.client.Result)444 Test (org.junit.Test)282 Table (org.apache.hadoop.hbase.client.Table)226 Put (org.apache.hadoop.hbase.client.Put)201 IOException (java.io.IOException)134 Cell (org.apache.hadoop.hbase.Cell)121 TableName (org.apache.hadoop.hbase.TableName)98 Connection (org.apache.hadoop.hbase.client.Connection)91 Delete (org.apache.hadoop.hbase.client.Delete)76 ArrayList (java.util.ArrayList)75 Configuration (org.apache.hadoop.conf.Configuration)72 Scan (org.apache.hadoop.hbase.client.Scan)57 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)52 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)38 CheckAndMutateResult (org.apache.hadoop.hbase.client.CheckAndMutateResult)38 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)36 Map (java.util.Map)34 Path (org.apache.hadoop.fs.Path)34 Admin (org.apache.hadoop.hbase.client.Admin)33