use of com.aerospike.client.Operation in project aerospike-client-java by aerospike.
the class MapOperation method create.
/**
* Create map create operation.
* Server creates map at given context level.
*/
public static Operation create(String binName, MapOrder order, CTX... ctx) {
// If context not defined, the set order for top-level bin map.
if (ctx == null || ctx.length == 0) {
return setMapPolicy(new MapPolicy(order, 0), binName);
}
Packer packer = new Packer();
CDT.init(packer, ctx, SET_TYPE, 1, order.flag);
packer.packInt(order.attributes);
return new Operation(Operation.Type.MAP_MODIFY, binName, Value.get(packer.toByteArray()));
}
use of com.aerospike.client.Operation in project aerospike-client-java by aerospike.
the class ListOperation method create.
/**
* Create list create operation.
* Server creates list at given context level. The context is allowed to be beyond list
* boundaries only if pad is set to true. In that case, nil list entries will be inserted to
* satisfy the context position.
*/
public static Operation create(String binName, ListOrder order, boolean pad, CTX... ctx) {
// If context not defined, the set order for top-level bin list.
if (ctx == null || ctx.length == 0) {
return setOrder(binName, order);
}
Packer packer = new Packer();
CDT.init(packer, ctx, SET_TYPE, 1, order.getFlag(pad));
packer.packInt(order.attributes);
return new Operation(Operation.Type.CDT_MODIFY, binName, Value.get(packer.toByteArray()));
}
use of com.aerospike.client.Operation in project aerospike-client-java by aerospike.
the class BatchOperate method batchReadOperateComplex.
/**
* Read results using varying read operations in one batch.
*/
private void batchReadOperateComplex(AerospikeClient client, Parameters params) {
console.info("batchReadOperateComplex");
Expression exp1 = Exp.build(Exp.mul(Exp.intBin(BinName1), Exp.intBin(BinName2)));
Expression exp2 = Exp.build(Exp.add(Exp.intBin(BinName1), Exp.intBin(BinName2)));
Expression exp3 = Exp.build(Exp.sub(Exp.intBin(BinName1), Exp.intBin(BinName2)));
// Batch uses pointer reference to quickly determine if operations are repeated and can therefore
// be optimized, but using varargs directly always creates a new reference. Therefore, save operation
// array so we have one pointer reference per operation array.
Operation[] ops1 = Operation.array(ExpOperation.read(ResultName1, exp1, ExpReadFlags.DEFAULT));
Operation[] ops2 = Operation.array(ExpOperation.read(ResultName1, exp2, ExpReadFlags.DEFAULT));
Operation[] ops3 = Operation.array(ExpOperation.read(ResultName1, exp3, ExpReadFlags.DEFAULT));
Operation[] ops4 = Operation.array(ExpOperation.read(ResultName1, exp2, ExpReadFlags.DEFAULT), ExpOperation.read(ResultName2, exp3, ExpReadFlags.DEFAULT));
List<BatchRead> records = new ArrayList<BatchRead>();
records.add(new BatchRead(new Key(params.namespace, params.set, KeyPrefix + 1), ops1));
// The following record is optimized (namespace,set,ops are only sent once) because
// namespace, set and ops all have the same pointer references as the previous entry.
records.add(new BatchRead(new Key(params.namespace, params.set, KeyPrefix + 2), ops1));
records.add(new BatchRead(new Key(params.namespace, params.set, KeyPrefix + 3), ops2));
records.add(new BatchRead(new Key(params.namespace, params.set, KeyPrefix + 4), ops3));
records.add(new BatchRead(new Key(params.namespace, params.set, KeyPrefix + 5), ops4));
// Execute batch.
client.get(null, records);
// Show results.
int count = 0;
for (BatchRead record : records) {
Record rec = record.record;
Object v1 = rec.getValue(ResultName1);
Object v2 = rec.getValue(ResultName2);
console.info("Result[%d]: %s, %s", count++, v1, v2);
}
}
use of com.aerospike.client.Operation in project aerospike-client-java by aerospike.
the class TestBatch method batchReadComplex.
@Test
public void batchReadComplex() {
// Batch allows multiple namespaces in one call, but example test environment may only have one namespace.
// bin * 8
Expression exp = Exp.build(Exp.mul(Exp.intBin(BinName), Exp.val(8)));
Operation[] ops = Operation.array(ExpOperation.read(BinName, exp, ExpReadFlags.DEFAULT));
String[] bins = new String[] { BinName };
List<BatchRead> records = new ArrayList<BatchRead>();
records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 1), bins));
records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 2), true));
records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 3), true));
records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 4), false));
records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 5), true));
records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 6), ops));
records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 7), bins));
// This record should be found, but the requested bin will not be found.
records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 8), new String[] { "binnotfound" }));
// This record should not be found.
records.add(new BatchRead(new Key(args.namespace, args.set, "keynotfound"), bins));
// Execute batch.
client.get(null, records);
assertBatchBinEqual(records, BinName, 0);
assertBatchBinEqual(records, BinName, 1);
assertBatchBinEqual(records, BinName, 2);
assertBatchRecordExists(records, BinName, 3);
assertBatchBinEqual(records, BinName, 4);
BatchRead batch = records.get(5);
assertRecordFound(batch.key, batch.record);
int v = batch.record.getInt(BinName);
assertEquals(48, v);
assertBatchBinEqual(records, BinName, 6);
batch = records.get(7);
assertRecordFound(batch.key, batch.record);
Object val = batch.record.getValue("binnotfound");
if (val != null) {
fail("Unexpected batch bin value received");
}
batch = records.get(8);
if (batch.record != null) {
fail("Unexpected batch record received");
}
}
use of com.aerospike.client.Operation in project aerospike-client-java by aerospike.
the class TestOperateHll method assertAddInit.
public void assertAddInit(int nIndexBits, int nMinhashBits) {
client.delete(null, key);
String msg = "Fail - nIdexBits " + nIndexBits + " nMinhashBits " + nMinhashBits;
HLLPolicy p = HLLPolicy.Default;
Operation[] ops = new Operation[] { HLLOperation.add(p, binName, entries, nIndexBits, nMinhashBits), HLLOperation.getCount(binName), HLLOperation.refreshCount(binName), HLLOperation.describe(binName), HLLOperation.add(p, binName, entries) };
if (!checkBits(nIndexBits, nMinhashBits)) {
assertThrows(msg, key, AerospikeException.class, ResultCode.PARAMETER_ERROR, ops);
return;
}
Record record = assertSuccess(msg, key, ops);
List<?> resultList = record.getList(binName);
long count = (Long) resultList.get(1);
long count1 = (Long) resultList.get(2);
List<?> description = (List<?>) resultList.get(3);
long nAdded = (Long) resultList.get(4);
assertDescription(msg, description, nIndexBits, nMinhashBits);
assertHLLCount(msg, nIndexBits, count, entries.size());
assertEquals(count, count1);
assertEquals(nAdded, 0);
}
Aggregations