use of com.aerospike.client.exp.Expression in project aerospike-client-java by aerospike.
the class TestExpOperation method expReadEvalError.
@Test
public void expReadEvalError() {
Expression exp = Exp.build(Exp.add(Exp.intBin(binA), Exp.val(4)));
Record record = client.operate(null, keyA, ExpOperation.read(expVar, exp, ExpReadFlags.DEFAULT));
assertRecordFound(keyA, record);
// System.out.println(record);
AerospikeException ae = assertThrows(AerospikeException.class, new ThrowingRunnable() {
public void run() {
// Bin AString doesn't exist on keyB.
client.operate(null, keyB, ExpOperation.read(expVar, exp, ExpReadFlags.DEFAULT));
}
});
assertEquals(ResultCode.OP_NOT_APPLICABLE, ae.getResultCode());
// Try NO_FAIL.
record = client.operate(null, keyB, ExpOperation.read(expVar, exp, ExpReadFlags.EVAL_NO_FAIL));
assertRecordFound(keyB, record);
// System.out.println(record);
}
use of com.aerospike.client.exp.Expression in project aerospike-client-java by aerospike.
the class TestExpOperation method expWriteEvalError.
@Test
public void expWriteEvalError() {
Expression wexp = Exp.build(Exp.add(Exp.intBin(binA), Exp.val(4)));
Expression rexp = Exp.build(Exp.intBin(binC));
Record record = client.operate(null, keyA, ExpOperation.write(binC, wexp, ExpReadFlags.DEFAULT), ExpOperation.read(expVar, rexp, ExpReadFlags.DEFAULT));
assertRecordFound(keyA, record);
// System.out.println(record);
AerospikeException ae = assertThrows(AerospikeException.class, new ThrowingRunnable() {
public void run() {
client.operate(null, keyB, ExpOperation.write(binC, wexp, ExpWriteFlags.DEFAULT), ExpOperation.read(expVar, rexp, ExpReadFlags.DEFAULT));
}
});
assertEquals(ResultCode.OP_NOT_APPLICABLE, ae.getResultCode());
// Add NO_FAIL.
record = client.operate(null, keyB, ExpOperation.write(binC, wexp, ExpWriteFlags.EVAL_NO_FAIL), ExpOperation.read(expVar, rexp, ExpReadFlags.EVAL_NO_FAIL));
assertRecordFound(keyB, record);
// System.out.println(record);
}
use of com.aerospike.client.exp.Expression in project aerospike-client-java by aerospike.
the class TestExpOperation method expReturnsFloat.
@Test
public void expReturnsFloat() {
Expression exp = Exp.build(Exp.add(Exp.toFloat(Exp.intBin(binA)), Exp.val(4.0)));
Record record = client.operate(null, keyA, ExpOperation.write(binC, exp, ExpWriteFlags.DEFAULT), Operation.get(binC), ExpOperation.read(expVar, exp, ExpReadFlags.DEFAULT));
assertRecordFound(keyA, record);
// System.out.println(record);
List<?> results = record.getList(binC);
double val = (Double) results.get(1);
double delta = 0.000001;
assertEquals(5.0, val, delta);
val = record.getDouble(expVar);
assertEquals(5.0, val, delta);
record = client.operate(null, keyA, ExpOperation.read(expVar, exp, ExpReadFlags.DEFAULT));
val = record.getDouble(expVar);
assertEquals(5.0, val, delta);
}
use of com.aerospike.client.exp.Expression in project aerospike-client-java by aerospike.
the class BatchOperate method batchReadOperate.
/**
* Perform read operation expressions in one batch.
*/
private void batchReadOperate(AerospikeClient client, Parameters params) {
console.info("batchReadOperate");
Key[] keys = new Key[RecordCount];
for (int i = 0; i < RecordCount; i++) {
keys[i] = new Key(params.namespace, params.set, KeyPrefix + (i + 1));
}
// bin1 * bin2
Expression exp = Exp.build(Exp.mul(Exp.intBin(BinName1), Exp.intBin(BinName2)));
Record[] records = client.get(null, keys, ExpOperation.read(ResultName1, exp, ExpReadFlags.DEFAULT));
for (int i = 0; i < records.length; i++) {
Record record = records[i];
console.info("Result[%d]: %d", i, record.getInt(ResultName1));
}
}
Aggregations