Search in sources :

Example 1 with DataSetException

use of io.cdap.cdap.api.dataset.DataSetException in project cdap by caskdata.

the class HBaseMetricsTable method incrementAndGet.

@Override
public long incrementAndGet(byte[] row, byte[] column, long delta) {
    byte[] distributedKey = createDistributedRowKey(row);
    Increment increment = new Increment(distributedKey);
    increment.addColumn(columnFamily, column, delta);
    try {
        Result result = table.increment(increment);
        return Bytes.toLong(result.getValue(columnFamily, column));
    } catch (IOException e) {
        // currently there is not other way to extract that from the HBase exception than string match
        if (e.getMessage() != null && e.getMessage().contains("isn't 64 bits wide")) {
            throw new NumberFormatException("Attempted to increment a value that is not convertible to long," + " row: " + Bytes.toStringBinary(distributedKey) + " column: " + Bytes.toStringBinary(column));
        }
        throw new DataSetException("IncrementAndGet failed on table " + tableId, e);
    }
}
Also used : DataSetException(io.cdap.cdap.api.dataset.DataSetException) Increment(org.apache.hadoop.hbase.client.Increment) IOException(java.io.IOException) Result(org.apache.hadoop.hbase.client.Result)

Example 2 with DataSetException

use of io.cdap.cdap.api.dataset.DataSetException in project cdap by caskdata.

the class ObjectStoreDataset method decode.

private T decode(byte[] bytes) {
    if (bytes == null) {
        return null;
    }
    // decode T using schema
    ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
    BinaryDecoder decoder = new BinaryDecoder(bis);
    try {
        return getReflectionDatumReader().read(decoder, this.schema);
    } catch (IOException e) {
        // SHOULD NEVER happen
        throw new DataSetException("Failed to decode read object: " + e.getMessage(), e);
    }
}
Also used : DataSetException(io.cdap.cdap.api.dataset.DataSetException) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) BinaryDecoder(io.cdap.cdap.common.io.BinaryDecoder)

Example 3 with DataSetException

use of io.cdap.cdap.api.dataset.DataSetException in project cdap by caskdata.

the class HBaseMetricsTable method putBytes.

@Override
public void putBytes(SortedMap<byte[], ? extends SortedMap<byte[], byte[]>> updates) {
    List<Put> puts = Lists.newArrayList();
    for (Map.Entry<byte[], ? extends SortedMap<byte[], byte[]>> row : updates.entrySet()) {
        byte[] distributedKey = createDistributedRowKey(row.getKey());
        PutBuilder put = tableUtil.buildPut(distributedKey);
        for (Map.Entry<byte[], byte[]> column : row.getValue().entrySet()) {
            put.add(columnFamily, column.getKey(), column.getValue());
        }
        puts.add(put.build());
    }
    try {
        mutator.mutate(puts);
        mutator.flush();
    } catch (IOException e) {
        throw new DataSetException("Put failed on table " + tableId, e);
    }
}
Also used : PutBuilder(io.cdap.cdap.data2.util.hbase.PutBuilder) DataSetException(io.cdap.cdap.api.dataset.DataSetException) IOException(java.io.IOException) Map(java.util.Map) NavigableMap(java.util.NavigableMap) SortedMap(java.util.SortedMap) Put(org.apache.hadoop.hbase.client.Put)

Example 4 with DataSetException

use of io.cdap.cdap.api.dataset.DataSetException in project cdap by caskdata.

the class HBaseMetricsTable method increment.

@Override
public void increment(byte[] row, Map<byte[], Long> increments) {
    byte[] distributedKey = createDistributedRowKey(row);
    Put increment = getIncrementalPut(distributedKey, increments);
    try {
        mutator.mutate(increment);
        mutator.flush();
    } catch (IOException e) {
        // currently there is not other way to extract that from the HBase exception than string match
        if (e.getMessage() != null && e.getMessage().contains("isn't 64 bits wide")) {
            throw new NumberFormatException("Attempted to increment a value that is not convertible to long," + " row: " + Bytes.toStringBinary(distributedKey));
        }
        throw new DataSetException("Increment failed on table " + tableId, e);
    }
}
Also used : DataSetException(io.cdap.cdap.api.dataset.DataSetException) IOException(java.io.IOException) Put(org.apache.hadoop.hbase.client.Put)

Example 5 with DataSetException

use of io.cdap.cdap.api.dataset.DataSetException in project cdap by caskdata.

the class HBaseMetricsTable method delete.

@Override
public void delete(byte[] row, byte[][] columns) {
    byte[] distributedKey = createDistributedRowKey(row);
    DeleteBuilder delete = tableUtil.buildDelete(distributedKey);
    for (byte[] column : columns) {
        delete.deleteColumns(columnFamily, column);
    }
    try {
        table.delete(delete.build());
    } catch (IOException e) {
        throw new DataSetException("Delete failed on table " + tableId, e);
    }
}
Also used : DataSetException(io.cdap.cdap.api.dataset.DataSetException) IOException(java.io.IOException) DeleteBuilder(io.cdap.cdap.data2.util.hbase.DeleteBuilder)

Aggregations

DataSetException (io.cdap.cdap.api.dataset.DataSetException)37 IOException (java.io.IOException)27 ReadOnly (io.cdap.cdap.api.annotation.ReadOnly)7 Map (java.util.Map)6 TransactionFailureException (org.apache.tephra.TransactionFailureException)6 Location (org.apache.twill.filesystem.Location)6 PartitionKey (io.cdap.cdap.api.dataset.lib.PartitionKey)5 Result (io.cdap.cdap.api.dataset.table.Result)5 NavigableMap (java.util.NavigableMap)5 Test (org.junit.Test)5 PartitionAlreadyExistsException (io.cdap.cdap.api.dataset.lib.PartitionAlreadyExistsException)4 TimePartitionedFileSet (io.cdap.cdap.api.dataset.lib.TimePartitionedFileSet)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 WriteOnly (io.cdap.cdap.api.annotation.WriteOnly)3 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)3 PartitionedFileSet (io.cdap.cdap.api.dataset.lib.PartitionedFileSet)3 Put (io.cdap.cdap.api.dataset.table.Put)3 Row (io.cdap.cdap.api.dataset.table.Row)3 DatasetId (io.cdap.cdap.proto.id.DatasetId)3 UnauthorizedException (io.cdap.cdap.security.spi.authorization.UnauthorizedException)3