use of com.aerospike.client.query.Statement in project aerospike-client-java by aerospike.
the class TestAsyncQuery method runQuery.
private void runQuery() {
int begin = 26;
int end = 34;
Statement stmt = new Statement();
stmt.setNamespace(args.namespace);
stmt.setSetName(args.set);
stmt.setBinNames(binName);
stmt.setFilter(Filter.range(binName, begin, end));
final AtomicInteger count = new AtomicInteger();
client.query(eventLoop, new RecordSequenceListener() {
public void onRecord(Key key, Record record) throws AerospikeException {
int result = record.getInt(binName);
assertBetween(26, 34, result);
count.incrementAndGet();
}
public void onSuccess() {
int size = count.get();
assertEquals(9, size);
notifyComplete();
}
public void onFailure(AerospikeException e) {
setError(e);
notifyComplete();
}
}, null, stmt);
}
use of com.aerospike.client.query.Statement in project aerospike-client-java by aerospike.
the class StoreKey method runQuery.
private void runQuery(AerospikeClient client, Parameters params, String indexName, String binName) throws Exception {
int begin = 2;
int end = 5;
console.info("Query user key for: ns=%s set=%s index=%s bin=%s >= %s <= %s", params.namespace, params.set, indexName, binName, begin, end);
Statement stmt = new Statement();
stmt.setNamespace(params.namespace);
stmt.setSetName(params.set);
stmt.setBinNames(binName);
stmt.setFilter(Filter.range(binName, begin, end));
RecordSet rs = client.query(null, stmt);
try {
int count = 0;
while (rs.next()) {
Key key = rs.getKey();
if (key.userKey != null) {
Object userkey = key.userKey.getObject();
Record record = rs.getRecord();
int result = record.getInt(binName);
if (userkey != null) {
console.info("Record found with user key: ns=%s set=%s bin=%s userkey=%s value=%s", key.namespace, key.setName, binName, userkey, result);
} else {
console.error("Record found with null user key: ns=%s set=%s bin=%s userkey=null value=%s", key.namespace, key.setName, binName, result);
}
} else {
console.error("Record found with null user key: ns=%s set=%s bin=%s userkey=null", key.namespace, key.setName, binName);
}
count++;
}
if (count != 4) {
console.error("Query count mismatch. Expected 4. Received " + count);
}
} finally {
rs.close();
}
}
use of com.aerospike.client.query.Statement in project aerospike-client-java by aerospike.
the class AsyncQuery method runQuery.
private void runQuery(AerospikeClient client, EventLoop eventLoop, final String binName) {
int begin = 26;
int end = 34;
console.info("Query for: ns=%s set=%s bin=%s >= %s <= %s", params.namespace, params.set, binName, begin, end);
Statement stmt = new Statement();
stmt.setNamespace(params.namespace);
stmt.setSetName(params.set);
stmt.setBinNames(binName);
stmt.setFilter(Filter.range(binName, begin, end));
final AtomicInteger count = new AtomicInteger();
client.query(eventLoop, new RecordSequenceListener() {
public void onRecord(Key key, Record record) throws AerospikeException {
int result = record.getInt(binName);
console.info("Record found: ns=%s set=%s bin=%s digest=%s value=%s", key.namespace, key.setName, binName, Buffer.bytesToHexString(key.digest), result);
count.incrementAndGet();
}
public void onSuccess() {
int size = count.get();
if (size != 9) {
console.error("Query count mismatch. Expected 9. Received " + size);
}
notifyComplete();
}
public void onFailure(AerospikeException e) {
console.error("Query failed: " + Util.getErrorMessage(e));
notifyComplete();
}
}, null, stmt);
}
use of com.aerospike.client.query.Statement in project aerospike-client-java by aerospike.
the class QueryExp method runQuery3.
private void runQuery3(AerospikeClient client, Parameters params, String binName) throws Exception {
int begin = 20;
int end = 30;
console.info("Query Predicate: bin3 contains string with 'prefix' and 'suffix'");
Statement stmt = new Statement();
stmt.setNamespace(params.namespace);
stmt.setSetName(params.set);
stmt.setFilter(Filter.range(binName, begin, end));
QueryPolicy policy = new QueryPolicy(client.queryPolicyDefault);
policy.filterExp = Exp.build(Exp.regexCompare("prefix.*suffix", RegexFlag.ICASE | RegexFlag.NEWLINE, Exp.stringBin("bin3")));
RecordSet rs = client.query(policy, stmt);
try {
while (rs.next()) {
Record record = rs.getRecord();
console.info("Record: " + record.toString());
}
} finally {
rs.close();
}
}
use of com.aerospike.client.query.Statement in project aerospike-client-java by aerospike.
the class QueryExp method runQuery2.
private void runQuery2(AerospikeClient client, Parameters params, String binName) throws Exception {
int begin = 10;
int end = 40;
console.info("Query Predicate: Record updated in 2020");
Calendar beginTime = new GregorianCalendar(2020, 0, 1);
Calendar endTime = new GregorianCalendar(2021, 0, 1);
Statement stmt = new Statement();
stmt.setNamespace(params.namespace);
stmt.setSetName(params.set);
stmt.setFilter(Filter.range(binName, begin, end));
QueryPolicy policy = new QueryPolicy(client.queryPolicyDefault);
policy.filterExp = Exp.build(Exp.and(Exp.ge(Exp.lastUpdate(), Exp.val(beginTime)), Exp.lt(Exp.lastUpdate(), Exp.val(endTime))));
RecordSet rs = client.query(policy, stmt);
try {
while (rs.next()) {
Record record = rs.getRecord();
console.info("Record: " + record.toString());
}
} finally {
rs.close();
}
}
Aggregations