Search in sources :

Example 66 with Statement

use of com.aerospike.client.query.Statement in project aerospike-client-java by aerospike.

the class TestQueryFilterExp method queryDigestModulo.

@Test
public void queryDigestModulo() {
    int begin = 1;
    int end = 10;
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(setName);
    stmt.setFilter(Filter.range(binName, begin, end));
    // Record key digest % 3 == 1
    QueryPolicy policy = new QueryPolicy();
    policy.filterExp = Exp.build(Exp.eq(Exp.digestModulo(3), Exp.val(1)));
    RecordSet rs = client.query(policy, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            // System.out.println(rs.getRecord().toString());
            count++;
        }
        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 67 with Statement

use of com.aerospike.client.query.Statement in project aerospike-client-java by aerospike.

the class TestQueryFilterExp method queryList3.

@Test
public void queryList3() {
    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[4] == 20
    QueryPolicy policy = new QueryPolicy();
    policy.filterExp = Exp.build(Exp.eq(ListExp.getByIndex(ListReturnType.VALUE, Exp.Type.INT, Exp.val(4), Exp.listBin("listbin")), Exp.val(20)));
    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 68 with Statement

use of com.aerospike.client.query.Statement in project aerospike-client-java by aerospike.

the class TestQueryFilterExp method queryMap1.

@Test
public void queryMap1() {
    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 key "B"
    QueryPolicy policy = new QueryPolicy();
    policy.filterExp = Exp.build(Exp.gt(MapExp.getByKey(MapReturnType.COUNT, Exp.Type.INT, Exp.val("B"), Exp.mapBin("mapbin")), 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 69 with Statement

use of com.aerospike.client.query.Statement in project aerospike-client-java by aerospike.

the class TestQueryFilterExp method queryMap3.

@Test
public void queryMap3() {
    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 does not contains key "D"
    QueryPolicy policy = new QueryPolicy();
    policy.filterExp = Exp.build(Exp.eq(MapExp.getByKey(MapReturnType.COUNT, Exp.Type.INT, Exp.val("D"), Exp.mapBin("mapbin")), Exp.val(0)));
    RecordSet rs = client.query(policy, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            // System.out.println(rs.getRecord().toString());
            count++;
        }
        assertEquals(8, 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 70 with Statement

use of com.aerospike.client.query.Statement in project aerospike-client-java by aerospike.

the class TestQueryFilterExp method queryMemorySize.

@Test
public void queryMemorySize() {
    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 disk/device for which memorySize() 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.memorySize(), 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)

Aggregations

Statement (com.aerospike.client.query.Statement)82 RecordSet (com.aerospike.client.query.RecordSet)63 Test (org.junit.Test)53 QueryPolicy (com.aerospike.client.policy.QueryPolicy)28 Record (com.aerospike.client.Record)23 Key (com.aerospike.client.Key)10 ResultSet (com.aerospike.client.query.ResultSet)9 Node (com.aerospike.client.cluster.Node)8 ExecuteTask (com.aerospike.client.task.ExecuteTask)8 AerospikeException (com.aerospike.client.AerospikeException)7 Map (java.util.Map)6 AerospikeClient (com.aerospike.client.AerospikeClient)4 Ignore (org.junit.Ignore)4 Bin (com.aerospike.client.Bin)3 GregorianCalendar (java.util.GregorianCalendar)3 RecordSequenceListener (com.aerospike.client.listener.RecordSequenceListener)2 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 HashMap (java.util.HashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2