use of com.aerospike.client.Record in project aerospike-client-java by aerospike.
the class TestQueryExecute method queryExecuteOperateExp.
@Test
public void queryExecuteOperateExp() {
String binName = "foo";
Expression exp = Exp.build(Exp.val("bar"));
int begin = 3;
int end = 9;
Statement stmt = new Statement();
stmt.setNamespace(args.namespace);
stmt.setSetName(args.set);
stmt.setFilter(Filter.range(binName1, begin, end));
ExecuteTask task = client.execute(null, stmt, ExpOperation.write(binName, exp, ExpWriteFlags.DEFAULT));
task.waitTillComplete(3000, 3000);
stmt = new Statement();
stmt.setNamespace(args.namespace);
stmt.setSetName(args.set);
stmt.setFilter(Filter.range(binName1, begin, end));
RecordSet rs = client.query(null, stmt);
try {
int count = 0;
while (rs.next()) {
Record record = rs.getRecord();
String value = record.getString(binName);
if (value == null) {
fail("Bin " + binName + " not found");
}
if (!value.equals("bar")) {
fail("Data mismatch. Expected bar. Received " + value);
}
count++;
}
assertEquals(end - begin + 1, count);
} finally {
rs.close();
}
}
use of com.aerospike.client.Record in project aerospike-client-java by aerospike.
the class TestListExp method modifyWithContext.
@Test
public void modifyWithContext() {
List<Value> listSubA = new ArrayList<Value>();
listSubA.add(Value.get("e"));
listSubA.add(Value.get("d"));
listSubA.add(Value.get("c"));
listSubA.add(Value.get("b"));
listSubA.add(Value.get("a"));
List<Value> listA = new ArrayList<Value>();
listA.add(Value.get("a"));
listA.add(Value.get("b"));
listA.add(Value.get("c"));
listA.add(Value.get("d"));
listA.add(Value.get(listSubA));
List<Value> listB = new ArrayList<Value>();
listB.add(Value.get("x"));
listB.add(Value.get("y"));
listB.add(Value.get("z"));
client.operate(null, keyA, ListOperation.appendItems(ListPolicy.Default, binA, listA), ListOperation.appendItems(ListPolicy.Default, binB, listB), Operation.put(new Bin(binC, "M")));
CTX ctx = CTX.listIndex(4);
Record record;
List<?> result;
policy.filterExp = Exp.build(Exp.eq(ListExp.size(// Temporarily append binB/binC to binA in expression.
ListExp.appendItems(ListPolicy.Default, Exp.listBin(binB), ListExp.append(ListPolicy.Default, Exp.stringBin(binC), Exp.listBin(binA), ctx), ctx), ctx), Exp.val(9)));
record = client.get(policy, keyA, binA);
assertRecordFound(keyA, record);
result = record.getList(binA);
assertEquals(5, result.size());
policy.filterExp = Exp.build(Exp.eq(ListExp.size(// Temporarily append local listB and local "M" string to binA in expression.
ListExp.appendItems(ListPolicy.Default, Exp.val(listB), ListExp.append(ListPolicy.Default, Exp.val("M"), Exp.listBin(binA), ctx), ctx), ctx), Exp.val(9)));
record = client.get(policy, keyA, binA);
assertRecordFound(keyA, record);
result = record.getList(binA);
assertEquals(5, result.size());
}
use of com.aerospike.client.Record in project aerospike-client-java by aerospike.
the class TestListExp method expReturnsList.
@Test
public void expReturnsList() {
List<Value> list = new ArrayList<Value>();
list.add(Value.get("a"));
list.add(Value.get("b"));
list.add(Value.get("c"));
list.add(Value.get("d"));
Expression exp = Exp.build(Exp.val(list));
Record record = client.operate(null, keyA, ExpOperation.write(binC, exp, ExpWriteFlags.DEFAULT), Operation.get(binC), ExpOperation.read("var", exp, ExpReadFlags.DEFAULT));
// System.out.println(record);
List<?> results = record.getList(binC);
assertEquals(2, results.size());
List<?> rlist = (List<?>) results.get(1);
assertEquals(4, rlist.size());
List<?> results2 = record.getList("var");
assertEquals(4, results2.size());
}
use of com.aerospike.client.Record in project aerospike-client-java by aerospike.
the class TestOperate method operate.
@Test
public void operate() {
// Write initial record.
Key key = new Key(args.namespace, args.set, "opkey");
Bin bin1 = new Bin("optintbin", 7);
Bin bin2 = new Bin("optstringbin", "string value");
client.put(null, key, bin1, bin2);
// Add integer, write new string and read record.
Bin bin3 = new Bin(bin1.name, 4);
Bin bin4 = new Bin(bin2.name, "new string");
Record record = client.operate(null, key, Operation.add(bin3), Operation.put(bin4), Operation.get());
assertBinEqual(key, record, bin3.name, 11);
assertBinEqual(key, record, bin4);
}
use of com.aerospike.client.Record in project aerospike-client-java by aerospike.
the class TestOperateHll method operateIntersectHLL.
@Test
public void operateIntersectHLL() {
String otherBinName = binName + "other";
for (ArrayList<Integer> desc : legalDescriptions) {
int indexBits = desc.get(0);
int minhashBits = desc.get(1);
if (minhashBits != 0) {
break;
}
Record record = assertSuccess("init", key, Operation.delete(), HLLOperation.add(HLLPolicy.Default, binName, entries, indexBits, minhashBits), Operation.get(binName), HLLOperation.add(HLLPolicy.Default, otherBinName, entries, indexBits, 4), Operation.get(otherBinName));
List<HLLValue> hlls = new ArrayList<HLLValue>();
List<HLLValue> hmhs = new ArrayList<HLLValue>();
List<?> resultList = record.getList(binName);
hlls.add((HLLValue) resultList.get(1));
hlls.add(hlls.get(0));
resultList = record.getList(otherBinName);
hmhs.add((HLLValue) resultList.get(1));
hmhs.add(hmhs.get(0));
record = assertSuccess("intersect", key, HLLOperation.getIntersectCount(binName, hlls), HLLOperation.getSimilarity(binName, hlls));
resultList = record.getList(binName);
long intersectCount = (Long) resultList.get(0);
assertTrue("intersect value too high", intersectCount < 1.8 * entries.size());
hlls.add(hlls.get(0));
assertThrows("Expect parameter error", key, AerospikeException.class, ResultCode.PARAMETER_ERROR, HLLOperation.getIntersectCount(binName, hlls));
assertThrows("Expect parameter error", key, AerospikeException.class, ResultCode.PARAMETER_ERROR, HLLOperation.getSimilarity(binName, hlls));
record = assertSuccess("intersect", key, HLLOperation.getIntersectCount(binName, hmhs), HLLOperation.getSimilarity(binName, hmhs));
resultList = record.getList(binName);
intersectCount = (Long) resultList.get(0);
assertTrue("intersect value too high", intersectCount < 1.8 * entries.size());
hmhs.add(hmhs.get(0));
assertThrows("Expect parameter error", key, AerospikeException.class, ResultCode.OP_NOT_APPLICABLE, HLLOperation.getIntersectCount(binName, hmhs));
assertThrows("Expect parameter error", key, AerospikeException.class, ResultCode.OP_NOT_APPLICABLE, HLLOperation.getSimilarity(binName, hmhs));
}
}
Aggregations