Search in sources :

Example 1 with PartitionNotFoundException

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);
}
Also used : PartitionNotFoundException(io.cdap.cdap.api.dataset.PartitionNotFoundException) Row(io.cdap.cdap.api.dataset.table.Row)

Example 2 with PartitionNotFoundException

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();
    }
}
Also used : PartitionNotFoundException(io.cdap.cdap.api.dataset.PartitionNotFoundException) TransactionContext(org.apache.tephra.TransactionContext) PartitionKey(io.cdap.cdap.api.dataset.lib.PartitionKey) PartitionedFileSet(io.cdap.cdap.api.dataset.lib.PartitionedFileSet) Test(org.junit.Test)

Example 3 with PartitionNotFoundException

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);
}
Also used : PartitionNotFoundException(io.cdap.cdap.api.dataset.PartitionNotFoundException) Row(io.cdap.cdap.api.dataset.table.Row) Put(io.cdap.cdap.api.dataset.table.Put)

Aggregations

PartitionNotFoundException (io.cdap.cdap.api.dataset.PartitionNotFoundException)3 Row (io.cdap.cdap.api.dataset.table.Row)2 PartitionKey (io.cdap.cdap.api.dataset.lib.PartitionKey)1 PartitionedFileSet (io.cdap.cdap.api.dataset.lib.PartitionedFileSet)1 Put (io.cdap.cdap.api.dataset.table.Put)1 TransactionContext (org.apache.tephra.TransactionContext)1 Test (org.junit.Test)1