Search in sources :

Example 31 with RecordSet

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();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) Record(com.aerospike.client.Record) RecordSet(com.aerospike.client.query.RecordSet) Key(com.aerospike.client.Key)

Example 32 with RecordSet

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();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) Record(com.aerospike.client.Record) RecordSet(com.aerospike.client.query.RecordSet) HashMap(java.util.HashMap) Map(java.util.Map)

Example 33 with RecordSet

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();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) Record(com.aerospike.client.Record) RecordSet(com.aerospike.client.query.RecordSet) Key(com.aerospike.client.Key)

Example 34 with RecordSet

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();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) Record(com.aerospike.client.Record) RecordSet(com.aerospike.client.query.RecordSet) Key(com.aerospike.client.Key)

Example 35 with RecordSet

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();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) Record(com.aerospike.client.Record) RecordSet(com.aerospike.client.query.RecordSet)

Aggregations

RecordSet (com.aerospike.client.query.RecordSet)65 Statement (com.aerospike.client.query.Statement)63 Test (org.junit.Test)43 QueryPolicy (com.aerospike.client.policy.QueryPolicy)28 Record (com.aerospike.client.Record)22 Key (com.aerospike.client.Key)9 AerospikeException (com.aerospike.client.AerospikeException)6 AerospikeClient (com.aerospike.client.AerospikeClient)4 ArrayList (java.util.ArrayList)3 GregorianCalendar (java.util.GregorianCalendar)3 Node (com.aerospike.client.cluster.Node)2 ExecuteTask (com.aerospike.client.task.ExecuteTask)2 Calendar (java.util.Calendar)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Bin (com.aerospike.client.Bin)1 Expression (com.aerospike.client.exp.Expression)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 AerospikeQueryResult (org.apache.gora.aerospike.query.AerospikeQueryResult)1