Search in sources :

Example 11 with QueryPolicy

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

the class TestQueryFilterExp method queryMap4.

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

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

the class TestQueryFilterSet method queryVoidTime.

@Test
public void queryVoidTime() {
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(set1);
    GregorianCalendar now = new GregorianCalendar();
    GregorianCalendar end = new GregorianCalendar();
    end.add(Calendar.MINUTE, 2);
    QueryPolicy policy = new QueryPolicy();
    policy.filterExp = Exp.build(Exp.and(Exp.ge(Exp.voidTime(), Exp.val(now)), Exp.lt(Exp.voidTime(), Exp.val(end))));
    RecordSet rs = client.query(policy, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            count++;
        }
        assertEquals(2, count);
    } finally {
        rs.close();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) GregorianCalendar(java.util.GregorianCalendar) RecordSet(com.aerospike.client.query.RecordSet) QueryPolicy(com.aerospike.client.policy.QueryPolicy) Test(org.junit.Test)

Example 13 with QueryPolicy

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

the class TestQueryFilterSet method querySetName.

@Test
public void querySetName() {
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    QueryPolicy policy = new QueryPolicy();
    policy.filterExp = Exp.build(Exp.eq(Exp.setName(), Exp.val(set2)));
    RecordSet rs = client.query(policy, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            count++;
        }
        assertEquals(3, 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 14 with QueryPolicy

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

the class TestQueryFilterSet method queryKeyString.

@Test
public void queryKeyString() {
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(set3);
    QueryPolicy policy = new QueryPolicy();
    policy.filterExp = Exp.build(Exp.regexCompare("^key-.*-35$", 0, Exp.key(Exp.Type.STRING)));
    RecordSet rs = client.query(policy, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            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 15 with QueryPolicy

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

the class TestQueryFilterSet method queryTTL.

@Test
public void queryTTL() {
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(set1);
    QueryPolicy policy = new QueryPolicy();
    policy.filterExp = Exp.build(Exp.le(Exp.ttl(), Exp.val(60)));
    RecordSet rs = client.query(policy, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            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)

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