Search in sources :

Example 1 with PartitionNotFoundException

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

Example 2 with PartitionNotFoundException

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

Example 3 with PartitionNotFoundException

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);
}
Also used : PartitionNotFoundException(co.cask.cdap.api.dataset.PartitionNotFoundException) DataSetException(co.cask.cdap.api.dataset.DataSetException) Row(co.cask.cdap.api.dataset.table.Row) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Put(co.cask.cdap.api.dataset.table.Put) WriteOnly(co.cask.cdap.api.annotation.WriteOnly)

Example 4 with PartitionNotFoundException

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

Aggregations

PartitionNotFoundException (co.cask.cdap.api.dataset.PartitionNotFoundException)4 Row (co.cask.cdap.api.dataset.table.Row)3 Put (co.cask.cdap.api.dataset.table.Put)2 WriteOnly (co.cask.cdap.api.annotation.WriteOnly)1 DataSetException (co.cask.cdap.api.dataset.DataSetException)1 PartitionKey (co.cask.cdap.api.dataset.lib.PartitionKey)1 PartitionedFileSet (co.cask.cdap.api.dataset.lib.PartitionedFileSet)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TransactionContext (org.apache.tephra.TransactionContext)1 Test (org.junit.Test)1