Search in sources :

Example 36 with RecordSet

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

the class QueryPredExp method runQuery2.

private void runQuery2(AerospikeClient client, Parameters params, String binName) throws Exception {
    int begin = 10;
    int end = 40;
    console.info("Query Predicate: Record updated on 2017-01-15");
    Calendar beginTime = new GregorianCalendar(2017, 0, 15);
    Calendar endTime = new GregorianCalendar(2017, 0, 16);
    Statement stmt = new Statement();
    stmt.setNamespace(params.namespace);
    stmt.setSetName(params.set);
    stmt.setFilter(Filter.range(binName, begin, end));
    stmt.setPredExp(PredExp.recLastUpdate(), PredExp.integerValue(beginTime), PredExp.integerGreaterEq(), PredExp.recLastUpdate(), PredExp.integerValue(endTime), PredExp.integerLess(), PredExp.and(2));
    RecordSet rs = client.query(null, 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) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Record(com.aerospike.client.Record) RecordSet(com.aerospike.client.query.RecordSet)

Example 37 with RecordSet

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

the class TestQueryPredExp method queryPredicate4.

@Test
public void queryPredicate4() {
    int begin = 1;
    int end = 10;
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(setName);
    stmt.setFilter(Filter.range(binName, begin, end));
    stmt.setPredExp(PredExp.integerVar("x"), PredExp.integerValue(4), PredExp.integerEqual(), PredExp.listBin("listbin"), PredExp.listIterateOr("x"));
    /*
		stmt.setPredicate(
			Predicate.listInclude("listbin", "x", Predicate.var("x").equal(4))
			);
		*/
    RecordSet rs = client.query(null, 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) Test(org.junit.Test)

Example 38 with RecordSet

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

the class TestQueryPredExp method queryPredicate9.

@Test
public void queryPredicate9() {
    int begin = 1;
    int end = 10;
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(setName);
    stmt.setFilter(Filter.range(binName, begin, end));
    stmt.setPredExp(PredExp.stringVar("x"), PredExp.stringValue("AAA"), PredExp.stringUnequal(), PredExp.mapBin("mapbin"), PredExp.mapValIterateAnd("x"));
    /*
		stmt.setPredicate(
			Predicate.mapValueExclude("mapbin", "x", Predicate.var("x").equal("AAA"))
			);
		*/
    RecordSet rs = client.query(null, 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) Test(org.junit.Test)

Example 39 with RecordSet

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

the class TestQueryPredExp method queryPredicate10.

@Test
public void queryPredicate10() {
    int begin = 1;
    int end = 10;
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(setName);
    stmt.setFilter(Filter.range(binName, begin, end));
    stmt.setPredExp(PredExp.recDigestModulo(3), PredExp.integerValue(1), PredExp.integerEqual());
    RecordSet rs = client.query(null, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            // System.out.println(rs.getRecord().toString());
            count++;
        }
        assertEquals(2, count);
    } finally {
        rs.close();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) RecordSet(com.aerospike.client.query.RecordSet) Test(org.junit.Test)

Example 40 with RecordSet

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

the class TestQueryPredExp method queryPredicate5.

@Test
public void queryPredicate5() {
    int begin = 1;
    int end = 10;
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(setName);
    stmt.setFilter(Filter.range(binName, begin, end));
    stmt.setPredExp(PredExp.integerVar("x"), PredExp.integerValue(5), PredExp.integerUnequal(), PredExp.listBin("listbin"), PredExp.listIterateAnd("x"));
    /*
		stmt.setPredicate(
			Predicate.listExclude("listbin", "x", Predicate.var("x").equal(5))
			);
		*/
    RecordSet rs = client.query(null, 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) Test(org.junit.Test)

Aggregations

RecordSet (com.aerospike.client.query.RecordSet)65 Statement (com.aerospike.client.query.Statement)63 Test (org.junit.Test)43 QueryPolicy (com.aerospike.client.policy.QueryPolicy)28 Record (com.aerospike.client.Record)22 Key (com.aerospike.client.Key)9 AerospikeException (com.aerospike.client.AerospikeException)6 AerospikeClient (com.aerospike.client.AerospikeClient)4 ArrayList (java.util.ArrayList)3 GregorianCalendar (java.util.GregorianCalendar)3 Node (com.aerospike.client.cluster.Node)2 ExecuteTask (com.aerospike.client.task.ExecuteTask)2 Calendar (java.util.Calendar)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Bin (com.aerospike.client.Bin)1 Expression (com.aerospike.client.exp.Expression)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 AerospikeQueryResult (org.apache.gora.aerospike.query.AerospikeQueryResult)1