use of io.cdap.cdap.api.dataset.table.Put in project cdap by caskdata.
the class IndexedTable method put.
@WriteOnly
@Override
public void put(byte[] row, byte[] column, byte[] value) {
Put put = new Put(row);
put.add(column, value);
put(put);
}
use of io.cdap.cdap.api.dataset.table.Put in project cdap by caskdata.
the class IndexedTable method compareAndSwap.
/**
* Perform a swap operation by primary key.
* Parameters are as if they were on a non-indexed table.
* Note that if the swap is on the secondary key column,
* then the index must be updated; otherwise, this is a
* pass-through to the underlying table.
*/
@ReadWrite
@Override
public boolean compareAndSwap(byte[] row, byte[] column, byte[] expected, byte[] newValue) {
// is the same as the new value, then the index is not affected either.
if (!indexedColumns.contains(column) || Arrays.equals(expected, newValue)) {
return table.compareAndSwap(row, column, expected, newValue);
}
// the swap is on the index column. it will only succeed if the current
// value matches the expected value of the swap. if that value is not null,
// then we must remove the row key from the index for that value.
Delete idxDelete = null;
if (expected != null) {
idxDelete = new Delete(createIndexKey(row, column, expected), IDX_COL);
}
// if the new value is not null, then we must add the rowkey to the index
// for that value.
Put idxPut = null;
if (newValue != null) {
idxPut = new Put(createIndexKey(row, column, newValue), IDX_COL, row);
}
// apply all operations to both tables
boolean success = table.compareAndSwap(row, column, expected, newValue);
if (!success) {
// do nothing: no changes
return false;
}
if (idxDelete != null) {
index.delete(idxDelete);
}
if (idxPut != null) {
index.put(idxPut);
}
return true;
}
use of io.cdap.cdap.api.dataset.table.Put in project cdap by caskdata.
the class IndexedTable method put.
@WriteOnly
@Override
public void put(byte[] row, byte[][] columns, byte[][] values) {
Put put = new Put(row);
for (int i = 0; i < columns.length; i++) {
put.add(columns[i], values[i]);
}
put(put);
}
use of io.cdap.cdap.api.dataset.table.Put in project cdap by caskdata.
the class MockAction method run.
@Override
public void run(ActionContext context) throws Exception {
context.execute(new TxRunnable() {
@Override
public void run(DatasetContext context) throws Exception {
Table table = context.getDataset(config.tableName);
Put put = new Put(config.rowKey);
put.add(config.columnKey, config.value);
table.put(put);
}
});
// Set the same value in the arguments as well.
context.getArguments().set(config.rowKey + config.columnKey, config.value);
if (config.argumentKey != null && config.argumentValue != null) {
if (!context.getArguments().get(config.argumentKey).equals(config.argumentValue)) {
throw new IllegalStateException(String.format("Expected %s to be present in the argument map with value %s.", config.argumentKey, config.argumentValue));
}
}
}
use of io.cdap.cdap.api.dataset.table.Put in project cdap by caskdata.
the class MetricsTableOnTable method putBytes.
@Override
public void putBytes(SortedMap<byte[], ? extends SortedMap<byte[], byte[]>> updates) {
for (Map.Entry<byte[], ? extends SortedMap<byte[], byte[]>> rowUpdate : updates.entrySet()) {
Put put = new Put(rowUpdate.getKey());
for (Map.Entry<byte[], byte[]> columnUpdate : rowUpdate.getValue().entrySet()) {
put.add(columnUpdate.getKey(), columnUpdate.getValue());
}
table.put(put);
}
}
Aggregations