Search in sources :

Example 1 with RecordSet

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

the class QueryPredExp method runQuery1.

private void runQuery1(AerospikeClient client, Parameters params, String binName) throws Exception {
    int begin = 10;
    int end = 40;
    console.info("Query Predicate: (bin2 > 126 && bin2 <= 140) or (bin2 = 360)");
    Statement stmt = new Statement();
    stmt.setNamespace(params.namespace);
    stmt.setSetName(params.set);
    // Filter applied on query itself.  Filter can only reference an indexed bin.
    stmt.setFilter(Filter.range(binName, begin, end));
    // Predicates are applied on query results on server side.
    // Predicates can reference any bin.
    stmt.setPredExp(PredExp.integerBin("bin2"), PredExp.integerValue(126), PredExp.integerGreater(), PredExp.integerBin("bin2"), PredExp.integerValue(140), PredExp.integerLessEq(), PredExp.and(2), PredExp.integerBin("bin2"), PredExp.integerValue(360), PredExp.integerEqual(), PredExp.or(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) Record(com.aerospike.client.Record) RecordSet(com.aerospike.client.query.RecordSet)

Example 2 with RecordSet

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

the class TestQueryPredExp method queryPredicate3.

@Test
public void queryPredicate3() {
    int begin = 10;
    int end = 45;
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(setName);
    stmt.setFilter(Filter.range(binName, begin, end));
    stmt.setPredExp(PredExp.recLastUpdate(), PredExp.integerValue(System.currentTimeMillis() * 1000000L + 100), PredExp.integerGreater());
    /*
		stmt.setPredicate(
			Predicate.recordLastUpdate().greaterThan(Predicate.nanos(System.currentTimeMillis() + 100))
			);
		*/
    RecordSet rs = client.query(null, stmt);
    try {
        while (rs.next()) {
        // Record record = rs.getRecord();
        // System.out.println(record.getValue(binName).toString() + ' ' + record.expiration);
        // count++;
        }
    // Do not asset count since some tests can run after this one.
    // assertEquals(0, count);
    } finally {
        rs.close();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) RecordSet(com.aerospike.client.query.RecordSet) Test(org.junit.Test)

Example 3 with RecordSet

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

the class TestQueryPredExp method queryPredicate7.

@Test
public void queryPredicate7() {
    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("BBB"), PredExp.stringEqual(), PredExp.mapBin("mapbin"), PredExp.mapValIterateOr("x"));
    /*
		stmt.setPredicate(
				Predicate.mapValueInclude("mapbin", "x", Predicate.var("x").equal("BBB"))
				);
		*/
    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 4 with RecordSet

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

the class TestQueryPredExp method queryPredicate2.

@Test
public void queryPredicate2() {
    int begin = 10;
    int end = 45;
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(setName);
    stmt.setFilter(Filter.range(binName, begin, end));
    stmt.setPredExp(PredExp.integerBin("bin2"), PredExp.integerValue(15), PredExp.integerGreaterEq(), PredExp.integerBin("bin2"), PredExp.integerValue(42), PredExp.integerLessEq(), PredExp.and(2), PredExp.not());
    /*
		stmt.setPredicate(
			Predicate.not(Predicate.bin("bin2").greaterThanOrEqual(15).and(Predicate.bin("bin2").lessThanOrEqual(42)))
			);
		*/
    RecordSet rs = client.query(null, 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) Test(org.junit.Test)

Example 5 with RecordSet

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

the class TestQueryPredExp method queryPredicate6.

@Test
public void queryPredicate6() {
    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("B"), PredExp.stringEqual(), PredExp.mapBin("mapbin"), PredExp.mapKeyIterateOr("x"));
    /*
		stmt.setPredicate(
			Predicate.mapKeyInclude("mapbin", "x", Predicate.var("x").equal("B"))
			);
		*/
    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)

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