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);
}
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);
}
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);
}
}
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 });
}
}
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);
}
Aggregations