Search in sources :

Example 16 with Statement

use of com.aerospike.client.query.Statement 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 17 with Statement

use of com.aerospike.client.query.Statement 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 18 with Statement

use of com.aerospike.client.query.Statement 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)

Example 19 with Statement

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

the class TestQueryPredExp method queryPredicate1.

@Test
public void queryPredicate1() {
    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(40), PredExp.integerGreater(), PredExp.integerBin("bin2"), PredExp.integerValue(44), PredExp.integerLess(), PredExp.and(2), PredExp.integerBin("bin2"), PredExp.integerValue(22), PredExp.integerEqual(), PredExp.integerBin("bin2"), PredExp.integerValue(9), PredExp.integerEqual(), PredExp.or(3), PredExp.integerBin(binName), PredExp.integerBin("bin2"), PredExp.integerEqual(), PredExp.and(2));
    /*
		stmt.setPredicate(
			Predicate.bin("bin2").greaterThan(40).and(Predicate.bin("bin2").lessThan(44))
			.or(Predicate.bin("bin2").equal(22))
			.or(Predicate.bin("bin2").equal(9))
			.and(Predicate.bin(binName, Predicate.Type.INTEGER).equal(Predicate.bin("bin2")))
			);
		*/
    RecordSet rs = client.query(null, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            // System.out.println(rs.getRecord().getValue(binName));
            count++;
        }
        // 22, 41, 42, 43
        assertEquals(4, count);
    } finally {
        rs.close();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) RecordSet(com.aerospike.client.query.RecordSet) Test(org.junit.Test)

Example 20 with Statement

use of com.aerospike.client.query.Statement in project apex-malhar by apache.

the class AerospikeTestUtils method checkEvents.

static boolean checkEvents() {
    long count = 0;
    AerospikeClient client = null;
    try {
        client = new AerospikeClient(NODE, PORT);
        Statement stmnt = new Statement();
        stmnt.setNamespace(NAMESPACE);
        stmnt.setSetName(SET_NAME);
        RecordSet rs = client.query(null, stmnt);
        while (rs.next()) {
            Record record = rs.getRecord();
            Key key = rs.getKey();
            if (!TestPOJO.check(key, record)) {
                return false;
            }
            count++;
        }
    } catch (AerospikeException e) {
        throw new RuntimeException("Error fetching records: ", e);
    } finally {
        if (null != client) {
            client.close();
        }
    }
    return NUM_TUPLES == count;
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) AerospikeException(com.aerospike.client.AerospikeException) Statement(com.aerospike.client.query.Statement) Record(com.aerospike.client.Record) RecordSet(com.aerospike.client.query.RecordSet) Key(com.aerospike.client.Key)

Aggregations

Statement (com.aerospike.client.query.Statement)43 RecordSet (com.aerospike.client.query.RecordSet)31 Record (com.aerospike.client.Record)18 Test (org.junit.Test)18 Key (com.aerospike.client.Key)10 AerospikeException (com.aerospike.client.AerospikeException)7 ResultSet (com.aerospike.client.query.ResultSet)7 Map (java.util.Map)6 AerospikeClient (com.aerospike.client.AerospikeClient)4 RecordSequenceListener (com.aerospike.client.listener.RecordSequenceListener)2 ExecuteTask (com.aerospike.client.task.ExecuteTask)2 HashMap (java.util.HashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 HashSet (java.util.HashSet)1