Search in sources :

Example 26 with TableId

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

the class AbstractHBaseTableUtilTest method testListAllInNamespace.

@Test
public void testListAllInNamespace() throws Exception {
    HBaseTableUtil tableUtil = getTableUtil();
    Set<TableId> fooNamespaceTableIds = ImmutableSet.of(TableId.from("foo", "some.table1"), TableId.from("foo", "other.table"), TableId.from("foo", "some.table2"));
    String fooNamespaceInHbase = String.format("%s_foo", getPrefix());
    Set<TableId> fooNamespaceHTableIds = ImmutableSet.of(TableId.from(fooNamespaceInHbase, "some.table1"), TableId.from(fooNamespaceInHbase, "other.table"), TableId.from(fooNamespaceInHbase, "some.table2"));
    createNamespace("foo");
    createNamespace("foo_bar");
    TableId tableIdInOtherNamespace = TableId.from("foo_bar", "my.dataset");
    TableId hTableIdInOtherNamespace = TableId.from(String.format("%s_foo_bar", getPrefix()), "my.dataset");
    List<ListenableFuture<TableId>> createFutures = new ArrayList<>();
    for (TableId tableId : fooNamespaceTableIds) {
        createFutures.add(createAsync(tableId));
    }
    createFutures.add(createAsync(tableIdInOtherNamespace));
    Futures.allAsList(createFutures).get(60, TimeUnit.SECONDS);
    Set<TableId> retrievedTableIds = ImmutableSet.copyOf(tableUtil.listTablesInNamespace(hAdmin, tableUtil.getHBaseNamespace(new NamespaceId("foo"))));
    Assert.assertEquals(fooNamespaceHTableIds, retrievedTableIds);
    Set<TableId> allTableIds = ImmutableSet.<TableId>builder().addAll(fooNamespaceHTableIds).add(hTableIdInOtherNamespace).build();
    Assert.assertEquals(allTableIds, ImmutableSet.copyOf(tableUtil.listTables(hAdmin)));
    Assert.assertEquals(4, hAdmin.listTables().length);
    tableUtil.deleteAllInNamespace(ddlExecutor, tableUtil.getHBaseNamespace(new NamespaceId("foo")), hAdmin.getConfiguration());
    Assert.assertEquals(1, hAdmin.listTables().length);
    drop(tableIdInOtherNamespace);
    Assert.assertEquals(0, hAdmin.listTables().length);
    deleteNamespace("foo_bar");
}
Also used : TableId(co.cask.cdap.data2.util.TableId) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Test(org.junit.Test)

Example 27 with TableId

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

Example 28 with TableId

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

the class AbstractHBaseTableUtilTest method drop.

private void drop(TableId tableId) throws IOException {
    HBaseTableUtil tableUtil = getTableUtil();
    TableId hTableId = tableUtil.createHTableId(new NamespaceId(tableId.getNamespace()), tableId.getTableName());
    tableUtil.dropTable(ddlExecutor, hTableId);
}
Also used : TableId(co.cask.cdap.data2.util.TableId) NamespaceId(co.cask.cdap.proto.id.NamespaceId)

Example 29 with TableId

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

the class AbstractHBaseTableUtilTest method testDropAllInOtherNamespaceWithPrefix.

@Test
public void testDropAllInOtherNamespaceWithPrefix() throws Exception {
    HBaseTableUtil tableUtil = getTableUtil();
    createNamespace("foonamespace");
    createNamespace("barnamespace");
    TableId tableIdWithOtherPrefix = TableId.from("foonamespace", "other.table");
    TableId tableIdInOtherNamespace = TableId.from("default", "some.table1");
    Futures.allAsList(createAsync(TableId.from("foonamespace", "some.table1")), createAsync(tableIdWithOtherPrefix), createAsync(TableId.from("foonamespace", "some.table2")), createAsync(tableIdInOtherNamespace)).get(60, TimeUnit.SECONDS);
    Assert.assertEquals(4, hAdmin.listTables().length);
    tableUtil.deleteAllInNamespace(ddlExecutor, tableUtil.getHBaseNamespace(new NamespaceId("foonamespace")), hAdmin.getConfiguration(), new Predicate<TableId>() {

        @Override
        public boolean apply(TableId input) {
            return input.getTableName().startsWith("some");
        }
    });
    Assert.assertEquals(2, hAdmin.listTables().length);
    Futures.allAsList(dropAsync(tableIdInOtherNamespace), dropAsync(tableIdWithOtherPrefix)).get(60, TimeUnit.SECONDS);
    Assert.assertEquals(0, hAdmin.listTables().length);
    deleteNamespace("foonamespace");
    deleteNamespace("barnamespace");
}
Also used : TableId(co.cask.cdap.data2.util.TableId) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Test(org.junit.Test)

Example 30 with TableId

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

the class AbstractHBaseTableUtilTest method truncate.

private void truncate(String namespace, String tableName) throws IOException {
    HBaseTableUtil tableUtil = getTableUtil();
    TableId hTableId = tableUtil.createHTableId(new NamespaceId(namespace), tableName);
    tableUtil.truncateTable(ddlExecutor, hTableId);
}
Also used : TableId(co.cask.cdap.data2.util.TableId) NamespaceId(co.cask.cdap.proto.id.NamespaceId)

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