Search in sources :

Example 31 with TableId

use of co.cask.cdap.data2.util.TableId in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method getTableId.

private TableId getTableId(String namespace, String tableName) throws IOException {
    HBaseTableUtil tableUtil = getTableUtil();
    List<TableId> tableIds = tableUtil.listTablesInNamespace(hAdmin, tableUtil.getHBaseNamespace(new NamespaceId(namespace)));
    for (TableId tId : tableIds) {
        if (tId.getTableName().endsWith(tableName)) {
            return tId;
        }
    }
    return null;
}
Also used : TableId(co.cask.cdap.data2.util.TableId) NamespaceId(co.cask.cdap.proto.id.NamespaceId)

Example 32 with TableId

use of co.cask.cdap.data2.util.TableId in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method exists.

private boolean exists(TableId tableId) throws IOException {
    HBaseTableUtil tableUtil = getTableUtil();
    TableId hTableId = tableUtil.createHTableId(new NamespaceId(tableId.getNamespace()), tableId.getTableName());
    return tableUtil.tableExists(hAdmin, hTableId);
}
Also used : TableId(co.cask.cdap.data2.util.TableId) NamespaceId(co.cask.cdap.proto.id.NamespaceId)

Example 33 with TableId

use of co.cask.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(co.cask.cdap.data2.util.TableId) NamespaceId(co.cask.cdap.proto.id.NamespaceId)

Example 34 with TableId

use of co.cask.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 (HTable table = tableUtil.createHTable(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(co.cask.cdap.data2.util.TableId) NamespaceId(co.cask.cdap.proto.id.NamespaceId) HTable(org.apache.hadoop.hbase.client.HTable) Put(org.apache.hadoop.hbase.client.Put)

Example 35 with TableId

use of co.cask.cdap.data2.util.TableId in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method testDropAllInDefaultNamespace.

@Test
public void testDropAllInDefaultNamespace() throws Exception {
    HBaseTableUtil tableUtil = getTableUtil();
    TableId tableIdInOtherNamespace = TableId.from("default2", "my.dataset");
    createNamespace("default2");
    Futures.allAsList(createAsync(TableId.from("default", "some.table1")), createAsync(TableId.from("default", "other.table")), createAsync(TableId.from("default", "some.table2")), createAsync(tableIdInOtherNamespace)).get(60, TimeUnit.SECONDS);
    Assert.assertEquals(4, hAdmin.listTables().length);
    tableUtil.deleteAllInNamespace(ddlExecutor, NamespaceId.DEFAULT.getEntityName(), hAdmin.getConfiguration());
    Assert.assertEquals(1, hAdmin.listTables().length);
    drop(tableIdInOtherNamespace);
    Assert.assertEquals(0, hAdmin.listTables().length);
    deleteNamespace("default2");
}
Also used : TableId(co.cask.cdap.data2.util.TableId) Test(org.junit.Test)

Aggregations

TableId (co.cask.cdap.data2.util.TableId)102 Test (org.junit.Test)49 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)41 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)39 Put (org.apache.hadoop.hbase.client.Put)34 NamespaceId (co.cask.cdap.proto.id.NamespaceId)26 Cell (org.apache.hadoop.hbase.Cell)24 Scan (org.apache.hadoop.hbase.client.Scan)23 HTableDescriptorBuilder (co.cask.cdap.data2.util.hbase.HTableDescriptorBuilder)20 RegionScanner (org.apache.hadoop.hbase.regionserver.RegionScanner)18 HBaseTableUtil (co.cask.cdap.data2.util.hbase.HBaseTableUtil)16 HBaseTableUtilFactory (co.cask.cdap.data2.util.hbase.HBaseTableUtilFactory)15 IOException (java.io.IOException)14 HTable (org.apache.hadoop.hbase.client.HTable)12 HBaseDDLExecutor (co.cask.cdap.spi.hbase.HBaseDDLExecutor)11 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)10 Delete (org.apache.hadoop.hbase.client.Delete)9 Result (org.apache.hadoop.hbase.client.Result)9 Path (org.apache.hadoop.fs.Path)8 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)8