Search in sources :

Example 76 with TableId

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

the class AbstractHBaseTableUtilTest method testHTableDescriptor.

@Test
public void testHTableDescriptor() throws IOException {
    HBaseTableUtil tableUtil = getTableUtil();
    TableId tableId = TableId.from("default", "test.dataset");
    create(tableId);
    HTableDescriptor tableDescriptor = tableUtil.getHTableDescriptor(hAdmin, tableId);
    Assert.assertEquals(ProjectInfo.getVersion().toString(), tableDescriptor.getValue(HBaseTableUtil.CDAP_VERSION));
    Assert.assertEquals(getPrefix(), tableDescriptor.getValue(Constants.Dataset.TABLE_PREFIX));
    TableName tableName = HTableNameConverter.toTableName(getPrefix(), tableId);
    ddlExecutor.disableTableIfEnabled(tableName.getNamespaceAsString(), tableName.getQualifierAsString());
    tableUtil.deleteTable(ddlExecutor, tableId);
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) TableName(org.apache.hadoop.hbase.TableName) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Example 77 with TableId

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

the class AbstractHBaseTableUtilTest method testGrant.

@Test
public void testGrant() throws Exception {
    String namespace = "perm";
    TableId tableId = TableId.from("perm", "priv");
    // create a namespace and table
    if (namespacesSupported()) {
        createNamespace(namespace);
    }
    create(tableId);
    Assert.assertTrue(exists(tableId));
    // attempt to assign invalid permissions to the namespace or the table
    try {
        ddlExecutor.grantPermissions(tableId.getNamespace(), null, ImmutableMap.of("joe", "iii"));
        Assert.fail("Grant should have failed with invalid permissions");
    } catch (IOException e) {
        Assert.assertTrue(e.getMessage().contains("Unknown Action"));
    }
    try {
        getTableUtil().grantPermissions(ddlExecutor, tableId, ImmutableMap.of("@readers", "RXT"));
        Assert.fail("Grant should have failed with invalid permissions");
    } catch (IOException e) {
        Assert.assertTrue(e.getMessage().contains("Unknown Action"));
    }
    // assign some privileges to the namespace
    ddlExecutor.grantPermissions(tableId.getNamespace(), null, ImmutableMap.of("joe", "RX", "@readers", "CA"));
    // assign some privileges to the table
    getTableUtil().grantPermissions(ddlExecutor, tableId, ImmutableMap.of("joe", "RWX", "@readers", "RX"));
    // clean up
    drop(tableId);
    deleteNamespace(namespace);
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) IOException(java.io.IOException) Test(org.junit.Test)

Example 78 with TableId

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

the class LevelDBTableCoreTest method testDeleteRows.

@Test
public void testDeleteRows() throws Exception {
    String tableName = "testDeleteRowsTable";
    TableId tableId = TableId.from("default", tableName);
    // Single value table
    {
        Assert.assertNull(service.getTableStats().get(tableId));
        service.ensureTableExists(tableName);
        LevelDBTableCore table = new LevelDBTableCore(tableName, service);
        writeData(table, rowNamePrefix, 32, colName, 1024, 1);
        List<byte[]> rowsToDelete = new ArrayList<byte[]>();
        rowsToDelete.add(getRowName(rowNamePrefix, 1).getBytes(StandardCharsets.UTF_8));
        rowsToDelete.add(getRowName(rowNamePrefix, 5).getBytes(StandardCharsets.UTF_8));
        rowsToDelete.add(getRowName(rowNamePrefix, 7).getBytes(StandardCharsets.UTF_8));
        table.deleteRows(rowsToDelete);
        try (Scanner scanner = table.scan(Bytes.toBytes(1L), null, null, null, null)) {
            Row row;
            while ((row = scanner.next()) != null) {
                String rowName = new String(row.getRow(), StandardCharsets.UTF_8);
                Assert.assertFalse(rowsToDelete.contains(rowName.getBytes(StandardCharsets.UTF_8)));
            }
        }
        service.dropTable(tableName);
    }
    // Multi-version value
    {
        Assert.assertNull(service.getTableStats().get(tableId));
        service.ensureTableExists(tableName);
        LevelDBTableCore table = new LevelDBTableCore(tableName, service);
        writeData(table, rowNamePrefix, 32, colName, 1024, 8);
        List<byte[]> rowsToDelete = new ArrayList<byte[]>();
        rowsToDelete.add(getRowName(rowNamePrefix, 1).getBytes(StandardCharsets.UTF_8));
        rowsToDelete.add(getRowName(rowNamePrefix, 5).getBytes(StandardCharsets.UTF_8));
        rowsToDelete.add(getRowName(rowNamePrefix, 7).getBytes(StandardCharsets.UTF_8));
        table.deleteRows(rowsToDelete);
        try (Scanner scanner = table.scan(null, null, null, null, null)) {
            Row row;
            while ((row = scanner.next()) != null) {
                String rowName = new String(row.getRow(), StandardCharsets.UTF_8);
                Assert.assertFalse(rowsToDelete.contains(rowName.getBytes(StandardCharsets.UTF_8)));
            }
        }
        service.dropTable(tableName);
    }
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) Scanner(io.cdap.cdap.api.dataset.table.Scanner) ArrayList(java.util.ArrayList) List(java.util.List) Row(io.cdap.cdap.api.dataset.table.Row) Test(org.junit.Test)

Example 79 with TableId

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

the class AbstractIncrementHandlerTest method testIncrements.

@Test
public void testIncrements() throws Exception {
    TableId tableId = TableId.from(NamespaceId.DEFAULT.getEntityName(), "incrementTest");
    createTable(tableId);
    try (Table table = new HBaseTableUtilFactory(cConf).get().createTable(conf, tableId)) {
        byte[] colA = Bytes.toBytes("a");
        byte[] row1 = Bytes.toBytes("row1");
        // test column containing only increments
        table.put(newIncrement(row1, colA, 1));
        table.put(newIncrement(row1, colA, 1));
        table.put(newIncrement(row1, colA, 1));
        assertColumn(table, row1, colA, 3);
        // test intermixed increments and puts
        table.put(tableUtil.buildPut(row1).add(FAMILY, colA, ts++, Bytes.toBytes(5L)).build());
        assertColumn(table, row1, colA, 5);
        table.put(newIncrement(row1, colA, 1));
        table.put(newIncrement(row1, colA, 1));
        assertColumn(table, row1, colA, 7);
        // test multiple increment columns
        byte[] row2 = Bytes.toBytes("row2");
        byte[] colB = Bytes.toBytes("b");
        // increment A and B twice at the same timestamp
        table.put(newIncrement(row2, colA, 1, 1));
        table.put(newIncrement(row2, colB, 1, 1));
        table.put(newIncrement(row2, colA, 2, 1));
        table.put(newIncrement(row2, colB, 2, 1));
        // increment A once more
        table.put(newIncrement(row2, colA, 1));
        assertColumns(table, row2, new byte[][] { colA, colB }, new long[] { 3, 2 });
        // overwrite B with a new put
        table.put(tableUtil.buildPut(row2).add(FAMILY, colB, ts++, Bytes.toBytes(10L)).build());
        assertColumns(table, row2, new byte[][] { colA, colB }, new long[] { 3, 10 });
    }
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) HBaseTable(io.cdap.cdap.data2.dataset2.lib.table.hbase.HBaseTable) Table(org.apache.hadoop.hbase.client.Table) HBaseTableUtilFactory(io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory) Test(org.junit.Test)

Example 80 with TableId

use of io.cdap.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(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