Search in sources :

Example 16 with Expression

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);
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Expression(com.aerospike.client.exp.Expression) Record(com.aerospike.client.Record) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Example 17 with Expression

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);
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Expression(com.aerospike.client.exp.Expression) Record(com.aerospike.client.Record) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Example 18 with Expression

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);
}
Also used : Expression(com.aerospike.client.exp.Expression) Record(com.aerospike.client.Record) Test(org.junit.Test)

Example 19 with Expression

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));
    }
}
Also used : Expression(com.aerospike.client.exp.Expression) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key)

Aggregations

Expression (com.aerospike.client.exp.Expression)19 Record (com.aerospike.client.Record)18 Test (org.junit.Test)17 AerospikeException (com.aerospike.client.AerospikeException)6 ThrowingRunnable (org.junit.function.ThrowingRunnable)5 Key (com.aerospike.client.Key)4 ArrayList (java.util.ArrayList)4 BatchRead (com.aerospike.client.BatchRead)3 Operation (com.aerospike.client.Operation)3 ListOperation (com.aerospike.client.cdt.ListOperation)3 ExpOperation (com.aerospike.client.exp.ExpOperation)3 Value (com.aerospike.client.Value)1 HLLValue (com.aerospike.client.Value.HLLValue)1 BatchListListener (com.aerospike.client.listener.BatchListListener)1 RecordSet (com.aerospike.client.query.RecordSet)1 Statement (com.aerospike.client.query.Statement)1 ExecuteTask (com.aerospike.client.task.ExecuteTask)1 List (java.util.List)1