Search in sources :

Example 1 with QueryPolicy

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);
    }
}
Also used : QueryPolicy(com.aerospike.client.policy.QueryPolicy)

Example 2 with QueryPolicy

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();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) RecordSet(com.aerospike.client.query.RecordSet) QueryPolicy(com.aerospike.client.policy.QueryPolicy) Test(org.junit.Test)

Example 3 with QueryPolicy

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();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) RecordSet(com.aerospike.client.query.RecordSet) QueryPolicy(com.aerospike.client.policy.QueryPolicy) Test(org.junit.Test)

Example 4 with QueryPolicy

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();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) RecordSet(com.aerospike.client.query.RecordSet) QueryPolicy(com.aerospike.client.policy.QueryPolicy) Test(org.junit.Test)

Example 5 with QueryPolicy

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();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) ArrayList(java.util.ArrayList) RecordSet(com.aerospike.client.query.RecordSet) QueryPolicy(com.aerospike.client.policy.QueryPolicy) Test(org.junit.Test)

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