Search in sources :

Example 71 with TableId

use of io.cdap.cdap.data2.util.TableId in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method disable.

private void disable(String namespace, String tableName) throws IOException {
    HBaseTableUtil tableUtil = getTableUtil();
    TableId hTableId = tableUtil.createHTableId(new NamespaceId(namespace), tableName);
    TableName name = HTableNameConverter.toTableName(getPrefix(), hTableId);
    ddlExecutor.disableTableIfEnabled(name.getNamespaceAsString(), name.getQualifierAsString());
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) TableName(org.apache.hadoop.hbase.TableName) NamespaceId(io.cdap.cdap.proto.id.NamespaceId)

Example 72 with TableId

use of io.cdap.cdap.data2.util.TableId in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method writeSome.

private void writeSome(String namespace, String tableName) throws IOException {
    HBaseTableUtil tableUtil = getTableUtil();
    TableId hTableId = tableUtil.createHTableId(new NamespaceId(namespace), tableName);
    try (Table table = tableUtil.createTable(TEST_HBASE.getConfiguration(), hTableId)) {
        // writing at least couple megs to reflect in "megabyte"-based metrics
        for (int i = 0; i < 8; i++) {
            Put put = new Put(Bytes.toBytes("row" + i));
            put.add(Bytes.toBytes("d"), Bytes.toBytes("col" + i), new byte[1024 * 1024]);
            table.put(put);
        }
    }
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) Table(org.apache.hadoop.hbase.client.Table) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Put(org.apache.hadoop.hbase.client.Put)

Example 73 with TableId

use of io.cdap.cdap.data2.util.TableId in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method testBackwardCompatibility.

@Test
public void testBackwardCompatibility() throws IOException, InterruptedException {
    HBaseTableUtil tableUtil = getTableUtil();
    String tablePrefix = cConf.get(Constants.Dataset.TABLE_PREFIX);
    TableId tableId = TableId.from("default", "my.dataset");
    TableId hTableId = tableUtil.createHTableId(new NamespaceId(tableId.getNamespace()), tableId.getTableName());
    create(tableId);
    TableId resultTableId = getTableId("default", "my.dataset");
    Assert.assertNotNull(resultTableId);
    Assert.assertEquals("default", resultTableId.getNamespace());
    Assert.assertEquals("cdap.user.my.dataset", HTableNameConverter.toHBaseTableName(tablePrefix, resultTableId));
    Assert.assertEquals(getTableNameAsString(tableId), Bytes.toString(tableUtil.createTable(TEST_HBASE.getConfiguration(), hTableId).getTableDescriptor().getTableName().getName()));
    drop(tableId);
    tableId = TableId.from("default", "system.queue.config");
    hTableId = tableUtil.createHTableId(new NamespaceId(tableId.getNamespace()), tableId.getTableName());
    create(tableId);
    resultTableId = getTableId("default", "system.queue.config");
    Assert.assertEquals("default", resultTableId.getNamespace());
    Assert.assertEquals("cdap.system.queue.config", HTableNameConverter.toHBaseTableName(tablePrefix, resultTableId));
    Assert.assertEquals(getTableNameAsString(tableId), Bytes.toString(tableUtil.createTable(TEST_HBASE.getConfiguration(), hTableId).getTableDescriptor().getTableName().getName()));
    drop(tableId);
    tableId = TableId.from("myspace", "could.be.any.table.name");
    hTableId = tableUtil.createHTableId(new NamespaceId(tableId.getNamespace()), tableId.getTableName());
    createNamespace("myspace");
    create(tableId);
    resultTableId = getTableId("myspace", "could.be.any.table.name");
    Assert.assertEquals("cdap_myspace", resultTableId.getNamespace());
    Assert.assertEquals("could.be.any.table.name", HTableNameConverter.toHBaseTableName(tablePrefix, resultTableId));
    Assert.assertEquals(getTableNameAsString(hTableId), Bytes.toString(tableUtil.createTable(TEST_HBASE.getConfiguration(), hTableId).getTableDescriptor().getTableName().getName()));
    drop(tableId);
    deleteNamespace("myspace");
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Test(org.junit.Test)

Example 74 with TableId

use of io.cdap.cdap.data2.util.TableId in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method getTableStats.

private HBaseTableUtil.TableStats getTableStats(String namespace, String tableName) throws IOException {
    HBaseTableUtil tableUtil = getTableUtil();
    // todo : should support custom table-prefix
    TableId tableId = tableUtil.createHTableId(new NamespaceId(namespace), tableName);
    Map<TableId, HBaseTableUtil.TableStats> statsMap = tableUtil.getTableStats(hAdmin);
    return statsMap.get(tableId);
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) NamespaceId(io.cdap.cdap.proto.id.NamespaceId)

Example 75 with TableId

use of io.cdap.cdap.data2.util.TableId in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method create.

private void create(TableId tableId) throws IOException {
    HBaseTableUtil tableUtil = getTableUtil();
    TableId htableId = tableUtil.createHTableId(new NamespaceId(tableId.getNamespace()), tableId.getTableName());
    ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder("d", hAdmin.getConfiguration());
    TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(htableId, cConf);
    tdBuilder.addColumnFamily(cfdBuilder.build());
    ddlExecutor.createTableIfNotExists(tdBuilder.build(), null);
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) NamespaceId(io.cdap.cdap.proto.id.NamespaceId)

Aggregations

TableId (co.cask.cdap.data2.util.TableId)102 Test (org.junit.Test)95 TableId (io.cdap.cdap.data2.util.TableId)78 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)60 Put (org.apache.hadoop.hbase.client.Put)57 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)55 Cell (org.apache.hadoop.hbase.Cell)42 Scan (org.apache.hadoop.hbase.client.Scan)40 RegionScanner (org.apache.hadoop.hbase.regionserver.RegionScanner)32 NamespaceId (co.cask.cdap.proto.id.NamespaceId)26 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)19 IOException (java.io.IOException)17 HTableDescriptorBuilder (io.cdap.cdap.data2.util.hbase.HTableDescriptorBuilder)16 Result (org.apache.hadoop.hbase.client.Result)16 Delete (org.apache.hadoop.hbase.client.Delete)15 Get (org.apache.hadoop.hbase.client.Get)14 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)14 HBaseTableUtil (io.cdap.cdap.data2.util.hbase.HBaseTableUtil)12 TableName (org.apache.hadoop.hbase.TableName)12 HTable (org.apache.hadoop.hbase.client.HTable)12