use of io.cdap.cdap.api.dataset.PartitionNotFoundException in project cdap by caskdata.
the class PartitionedFileSetDataset method removeMetadata.
@Override
public void removeMetadata(PartitionKey key, Set<String> metadataKeys) {
final byte[] rowKey = generateRowKey(key, partitioning);
Row row = partitionsTable.get(rowKey);
if (row.isEmpty()) {
throw new PartitionNotFoundException(key, getName());
}
int i = 0;
byte[][] deleteColumns = new byte[metadataKeys.size()][];
for (String metadataKey : metadataKeys) {
deleteColumns[i++] = columnKeyFromMetadataKey(metadataKey);
}
partitionsTable.delete(rowKey, deleteColumns);
}
use of io.cdap.cdap.api.dataset.PartitionNotFoundException in project cdap by caskdata.
the class PartitionedFileSetTest method testMetadataForNonexistentPartition.
@Test
public void testMetadataForNonexistentPartition() throws Exception {
PartitionedFileSet pfs = dsFrameworkUtil.getInstance(pfsInstance);
PartitionKey key = generateUniqueKey();
TransactionContext txContext = new TransactionContext(txClient, (TransactionAware) pfs);
txContext.start();
try {
// didn't add any partitions to the dataset, so any partition key should throw a PartitionNotFoundException
pfs.addMetadata(key, "metaKey", "metaValue");
Assert.fail("Expected not to find key: " + key);
} catch (PartitionNotFoundException e) {
Assert.assertEquals(pfsInstance.getEntityName(), e.getPartitionedFileSetName());
Assert.assertEquals(key, e.getPartitionKey());
} finally {
txContext.abort();
}
}
use of io.cdap.cdap.api.dataset.PartitionNotFoundException in project cdap by caskdata.
the class PartitionedFileSetDataset method setMetadata.
private void setMetadata(PartitionKey key, Map<String, String> metadata, boolean allowUpdates) {
final byte[] rowKey = generateRowKey(key, partitioning);
Row row = partitionsTable.get(rowKey);
if (row.isEmpty()) {
throw new PartitionNotFoundException(key, getName());
}
Put put = new Put(rowKey);
addMetadataToPut(row, metadata, put, allowUpdates);
partitionsTable.put(put);
}
Aggregations