use of com.aerospike.client.query.RecordSet in project aerospike-client-java by aerospike.
the class TestQueryExecute method queryExecuteOperate.
@Test
public void queryExecuteOperate() {
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));
Bin bin = new Bin("foo", "bar");
ExecuteTask task = client.execute(null, stmt, Operation.put(bin));
task.waitTillComplete(3000, 3000);
String expected = bin.value.toString();
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(bin.name);
if (value == null) {
fail("Bin " + bin.name + " not found");
}
if (!value.equals(expected)) {
fail("Data mismatch. Expected " + expected + ". Received " + value);
}
count++;
}
assertEquals(end - begin + 1, count);
} finally {
rs.close();
}
}
use of com.aerospike.client.query.RecordSet 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.query.RecordSet in project aerospike-client-java by aerospike.
the class TestQueryFilterExp method queryDeviceSize.
@Test
public void queryDeviceSize() {
int begin = 1;
int end = 10;
Statement stmt = new Statement();
stmt.setNamespace(args.namespace);
stmt.setSetName(setName);
stmt.setFilter(Filter.range(binName, begin, end));
// storage-engine could be memory for which deviceSize() returns zero.
// This just tests that the expression was sent correctly
// because all device sizes are effectively allowed.
QueryPolicy policy = new QueryPolicy();
policy.filterExp = Exp.build(Exp.ge(Exp.deviceSize(), Exp.val(0)));
RecordSet rs = client.query(policy, stmt);
try {
int count = 0;
while (rs.next()) {
count++;
}
assertEquals(10, count);
} finally {
rs.close();
}
}
use of com.aerospike.client.query.RecordSet in project aerospike-client-java by aerospike.
the class TestQueryFilterExp method queryList1.
@Test
public void queryList1() {
int begin = 1;
int end = 10;
Statement stmt = new Statement();
stmt.setNamespace(args.namespace);
stmt.setSetName(setName);
stmt.setFilter(Filter.range(binName, begin, end));
// List bin contains at least one integer item == 4
QueryPolicy policy = new QueryPolicy();
policy.filterExp = Exp.build(Exp.gt(ListExp.getByValue(ListReturnType.COUNT, Exp.val(4), Exp.listBin("listbin")), Exp.val(0)));
RecordSet rs = client.query(policy, stmt);
try {
int count = 0;
while (rs.next()) {
// System.out.println(rs.getRecord().toString());
count++;
}
assertEquals(1, count);
} finally {
rs.close();
}
}
use of com.aerospike.client.query.RecordSet in project aerospike-client-java by aerospike.
the class TestQueryFilterExp method queryMap6.
@Test
public void queryMap6() {
int begin = 1;
int end = 10;
Statement stmt = new Statement();
stmt.setNamespace(args.namespace);
stmt.setSetName(setName);
stmt.setFilter(Filter.range(binName, begin, end));
// Map bin contains keys "A" and "C".
QueryPolicy policy = new QueryPolicy();
List<String> list = new ArrayList<String>();
list.add("A");
list.add("C");
policy.filterExp = Exp.build(Exp.eq(// return type VALUE returns a list
ListExp.size(MapExp.getByKeyList(MapReturnType.VALUE, Exp.val(list), Exp.mapBin("mapbin"))), Exp.val(2)));
RecordSet rs = client.query(policy, stmt);
try {
int count = 0;
while (rs.next()) {
// System.out.println(rs.getRecord().toString());
count++;
}
assertEquals(1, count);
} finally {
rs.close();
}
}
Aggregations