use of co.cask.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);
}
use of co.cask.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 co.cask.cdap.api.dataset.PartitionNotFoundException in project cdap by caskdata.
the class PartitionedFileSetDataset method addMetadata.
@WriteOnly
@Override
public void addMetadata(PartitionKey key, Map<String, String> metadata) {
final byte[] rowKey = generateRowKey(key, partitioning);
Row row = partitionsTable.get(rowKey);
if (row.isEmpty()) {
throw new PartitionNotFoundException(key, getName());
}
// ensure that none of the entries already exist in the metadata
for (Map.Entry<String, String> metadataEntry : metadata.entrySet()) {
String metadataKey = metadataEntry.getKey();
byte[] columnKey = columnKeyFromMetadataKey(metadataKey);
if (row.get(columnKey) != null) {
throw new DataSetException(String.format("Entry already exists for metadata key: %s", metadataKey));
}
}
Put put = new Put(rowKey);
addMetadataToPut(metadata, put);
partitionsTable.put(put);
}
use of co.cask.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);
}
Aggregations