Search in sources :

Example 6 with QueryPolicy

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

the class TestQueryFilterExp method queryList2.

@Test
public void queryList2() {
    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 does not contain integer item == 5
    QueryPolicy policy = new QueryPolicy();
    policy.filterExp = Exp.build(Exp.eq(ListExp.getByValue(ListReturnType.COUNT, Exp.val(5), 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(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 7 with QueryPolicy

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

the class TestQueryFilterExp method queryNot.

@Test
public void queryNot() {
    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 >= 15 && bin2 <= 42)
    QueryPolicy policy = new QueryPolicy();
    policy.filterExp = Exp.build(Exp.not(Exp.and(Exp.ge(Exp.intBin("bin2"), Exp.val(15)), Exp.le(Exp.intBin("bin2"), Exp.val(42)))));
    RecordSet rs = client.query(policy, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            // System.out.println(rs.getRecord().getValue(binName));
            count++;
        }
        // 10, 11, 12, 13, 43, 44, 45
        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 8 with QueryPolicy

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

the class TestQueryFilterExp method queryMap5.

@Test
public void queryMap5() {
    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(MapExp.size(MapExp.getByKeyList(MapReturnType.KEY_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)

Example 9 with QueryPolicy

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

the class TestQueryFilterExp method queryMap2.

@Test
public void queryMap2() {
    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 value "BBB"
    QueryPolicy policy = new QueryPolicy();
    policy.filterExp = Exp.build(Exp.gt(MapExp.getByValue(MapReturnType.COUNT, Exp.val("BBB"), 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 10 with QueryPolicy

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

the class TestQueryFilterExp method queryBinExists.

@Test
public void queryBinExists() {
    int begin = 1;
    int end = 10;
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(setName);
    stmt.setFilter(Filter.range(binName, begin, end));
    QueryPolicy policy = new QueryPolicy();
    policy.filterExp = Exp.build(Exp.binExists("bin2"));
    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

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