Search in sources :

Example 31 with QueryPolicy

use of com.aerospike.client.policy.QueryPolicy in project aerospike-client-java by aerospike.

the class QueryExp method runQuery1.

private void runQuery1(AerospikeClient client, Parameters params, String binName) throws Exception {
    int begin = 10;
    int end = 40;
    console.info("Query Predicate: (bin2 > 126 && bin2 <= 140) || (bin2 = 360)");
    Statement stmt = new Statement();
    stmt.setNamespace(params.namespace);
    stmt.setSetName(params.set);
    // Filter applied on query itself.  Filter can only reference an indexed bin.
    stmt.setFilter(Filter.range(binName, begin, end));
    // Predicates are applied on query results on server side.
    // Predicates can reference any bin.
    QueryPolicy policy = new QueryPolicy(client.queryPolicyDefault);
    policy.filterExp = Exp.build(Exp.or(Exp.and(Exp.gt(Exp.intBin("bin2"), Exp.val(126)), Exp.le(Exp.intBin("bin2"), Exp.val(140))), Exp.eq(Exp.intBin("bin2"), Exp.val(360))));
    RecordSet rs = client.query(policy, 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) QueryPolicy(com.aerospike.client.policy.QueryPolicy)

Aggregations

QueryPolicy (com.aerospike.client.policy.QueryPolicy)31 RecordSet (com.aerospike.client.query.RecordSet)28 Statement (com.aerospike.client.query.Statement)28 Test (org.junit.Test)25 Record (com.aerospike.client.Record)3 Filter (com.aerospike.client.query.Filter)2 IndexCollectionType (com.aerospike.client.query.IndexCollectionType)2 PredExp (com.aerospike.client.query.PredExp)2 ArrayList (java.util.ArrayList)2 GregorianCalendar (java.util.GregorianCalendar)2 Operation (com.aerospike.client.Operation)1 CommandExp (com.aerospike.client.exp.CommandExp)1 PartitionStatus (com.aerospike.client.query.PartitionStatus)1 Calendar (java.util.Calendar)1