use of com.aerospike.client.query.RecordSet in project aerospike-client-java by aerospike.
the class QueryString method runQuery.
private void runQuery(AerospikeClient client, Parameters params, String indexName, String binName, String valuePrefix) throws Exception {
String filter = valuePrefix + 3;
console.info("Query for: ns=%s set=%s index=%s bin=%s filter=%s", params.namespace, params.set, indexName, binName, filter);
Statement stmt = new Statement();
stmt.setNamespace(params.namespace);
stmt.setSetName(params.set);
stmt.setBinNames(binName);
stmt.setFilter(Filter.equal(binName, filter));
RecordSet rs = client.query(null, stmt);
try {
int count = 0;
while (rs.next()) {
Key key = rs.getKey();
Record record = rs.getRecord();
String result = record.getString(binName);
if (result.equals(filter)) {
console.info("Record found: ns=%s set=%s bin=%s key=%s value=%s", key.namespace, key.setName, binName, Buffer.bytesToHexString(key.digest), result);
} else {
console.error("Query mismatch: Expected %s. Received %s.", filter, result);
}
count++;
}
if (count == 0) {
console.error("Query failed. No records returned.");
}
} finally {
rs.close();
}
}
use of com.aerospike.client.query.RecordSet in project aerospike-client-java by aerospike.
the class QueryCollection method runQuery.
private void runQuery(AerospikeClient client, Parameters params, String indexName, String binName, String queryMapKey) throws Exception {
console.info("Query for: ns=%s set=%s index=%s bin=%s mapkey contains=%s", params.namespace, params.set, indexName, binName, queryMapKey);
Statement stmt = new Statement();
stmt.setNamespace(params.namespace);
stmt.setSetName(params.set);
stmt.setBinNames(binName);
stmt.setFilter(Filter.contains(binName, IndexCollectionType.MAPKEYS, queryMapKey));
RecordSet rs = client.query(null, stmt);
try {
int count = 0;
while (rs.next()) {
// Key key = rs.getKey();
Record record = rs.getRecord();
Map<?, ?> result = (Map<?, ?>) record.getValue(binName);
if (result.containsKey(queryMapKey)) {
/*console.info("Record found: ns=%s set=%s bin=%s key=%s value=%s",
key.namespace, key.setName, binName, Buffer.bytesToHexString(key.digest), result);
*/
} else {
console.error("Query mismatch: Expected mapKey %s. Received %s.", queryMapKey, result);
}
count++;
}
if (count == 0) {
console.error("Query failed. No records returned.");
} else {
console.info("Number of records %d", count);
}
} finally {
rs.close();
}
}
use of com.aerospike.client.query.RecordSet in project aerospike-client-java by aerospike.
the class QueryExecute method validateRecords.
private void validateRecords(AerospikeClient client, Parameters params, String indexName, String binName1, String binName2, int size) throws Exception {
int begin = 1;
int end = size + 100;
console.info("Validate records");
Statement stmt = new Statement();
stmt.setNamespace(params.namespace);
stmt.setSetName(params.set);
stmt.setFilter(Filter.range(binName1, begin, end));
RecordSet rs = client.query(null, stmt);
try {
int[] expectedList = new int[] { 1, 2, 3, 104, 5, 106, 7, 108, -1, 10 };
int expectedSize = size - 1;
int count = 0;
while (rs.next()) {
Key key = rs.getKey();
Record record = rs.getRecord();
int value1 = record.getInt(binName1);
int value2 = record.getInt(binName2);
console.info("Record found: ns=%s set=%s bin1=%s value1=%s bin2=%s value2=%s", key.namespace, key.setName, binName1, value1, binName2, value2);
int val1 = value1;
if (val1 == 9) {
console.error("Data mismatch. value1 " + val1 + " should not exist");
break;
}
if (val1 == 5) {
if (value2 != 0) {
console.error("Data mismatch. value2 " + value2 + " should be null");
break;
}
} else if (value1 != expectedList[value2 - 1]) {
console.error("Data mismatch. Expected " + expectedList[value2 - 1] + ". Received " + value1);
break;
}
count++;
}
if (count != expectedSize) {
console.error("Query count mismatch. Expected " + expectedSize + ". Received " + count);
}
} finally {
rs.close();
}
}
use of com.aerospike.client.query.RecordSet in project aerospike-client-java by aerospike.
the class QueryInteger method runQuery.
private void runQuery(AerospikeClient client, Parameters params, String indexName, String binName) throws Exception {
int begin = 14;
int end = 18;
console.info("Query 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();
Record record = rs.getRecord();
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++;
}
if (count != 5) {
console.error("Query count mismatch. Expected 5. Received " + count);
}
} finally {
rs.close();
}
}
use of com.aerospike.client.query.RecordSet in project aerospike-client-java by aerospike.
the class QueryPredExp 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));
stmt.setPredExp(PredExp.stringBin("bin3"), PredExp.stringValue("prefix.*suffix"), PredExp.stringRegex(RegexFlag.ICASE | RegexFlag.NEWLINE));
RecordSet rs = client.query(null, stmt);
try {
while (rs.next()) {
Record record = rs.getRecord();
console.info("Record: " + record.toString());
}
} finally {
rs.close();
}
}
Aggregations