use of com.aerospike.client.policy.QueryPolicy in project aerospike-client-java by aerospike.
the class AsyncClient method query.
// -------------------------------------------------------
// Query Operations
// -------------------------------------------------------
/**
* Asynchronously execute query on all server nodes. The query policy's
* <code>maxConcurrentNodes</code> dictate how many nodes can be queried in parallel.
* The default is to query all nodes in parallel.
* <p>
* This method schedules the node's query commands with channel selectors and returns.
* Selector threads will process the commands and send the results to the listener.
*
* @param policy query configuration parameters, pass in null for defaults
* @param listener where to send results
* @param statement database query command parameters
* @throws AerospikeException if query fails
*/
public final void query(final QueryPolicy policy, final RecordSequenceListener listener, final Statement statement) throws AerospikeException {
final QueryPolicy qp = (policy != null) ? policy : asyncQueryPolicyDefault;
if (useListener) {
// Reserve one command for each node.
final int commands = cluster.getNodes().length;
commandBegin(commands, new Runnable() {
public void run() {
query(findEventLoop(), new ARecordSequenceListener(listener, commands), qp, statement);
}
});
} else {
query(findEventLoop(), listener, qp, statement);
}
}
use of com.aerospike.client.policy.QueryPolicy in project aerospike-client-java by aerospike.
the class TestQueryFilterExp method queryAndOr.
@Test
public void queryAndOr() {
int begin = 10;
int end = 45;
Statement stmt = new Statement();
stmt.setNamespace(args.namespace);
stmt.setSetName(setName);
stmt.setFilter(Filter.range(binName, begin, end));
// ((bin2 > 40 && bin2 < 44) || bin2 == 22 || bin2 == 9) && (binName == bin2)
QueryPolicy policy = new QueryPolicy();
policy.filterExp = Exp.build(Exp.and(Exp.or(Exp.and(Exp.gt(Exp.intBin("bin2"), Exp.val(40)), Exp.lt(Exp.intBin("bin2"), Exp.val(44))), Exp.eq(Exp.intBin("bin2"), Exp.val(22)), Exp.eq(Exp.intBin("bin2"), Exp.val(9))), Exp.eq(Exp.intBin(binName), Exp.intBin("bin2"))));
RecordSet rs = client.query(policy, stmt);
try {
int count = 0;
while (rs.next()) {
// System.out.println(rs.getRecord().getValue(binName));
count++;
}
// 22, 41, 42, 43
assertEquals(4, count);
} finally {
rs.close();
}
}
use of com.aerospike.client.policy.QueryPolicy 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.policy.QueryPolicy 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.policy.QueryPolicy 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