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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations