Search in sources :

Example 6 with RecordSet

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

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

Example 8 with RecordSet

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

the class AbstractAerospikeGetOperator method emitTuples.

/**
 * This executes the query to retrieve result from database.
 * It then converts each row into tuple and emit that into output port.
 */
@Override
public void emitTuples() {
    Statement query = queryToRetrieveData();
    logger.debug(String.format("select statement: %s", query.toString()));
    RecordSet rs;
    try {
        rs = store.getClient().query(null, query);
        while (rs.next()) {
            Record rec = rs.getRecord();
            T tuple = getTuple(rec);
            outputPort.emit(tuple);
        }
    } catch (Exception ex) {
        store.disconnect();
        DTThrowable.rethrow(ex);
    }
}
Also used : Statement(com.aerospike.client.query.Statement) Record(com.aerospike.client.Record) RecordSet(com.aerospike.client.query.RecordSet)

Example 9 with RecordSet

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

the class AerospikeTransactionalStore method getCommittedWindowId.

@Override
public long getCommittedWindowId(String appId, int operatorId) {
    try {
        lastWindowFetchCommand.setFilters(Filter.equal(metaTableOperatorIdColumn, operatorId));
        lastWindowFetchCommand.setFilters(Filter.equal(metaTableAppIdColumn, appId));
        long lastWindow = -1;
        RecordSet recordSet = client.query(null, lastWindowFetchCommand);
        while (recordSet.next()) {
            lastWindow = Long.parseLong(recordSet.getRecord().getValue(metaTableWindowColumn).toString());
        }
        return lastWindow;
    } catch (AerospikeException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) RecordSet(com.aerospike.client.query.RecordSet)

Example 10 with RecordSet

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

the class TestQueryCollection method queryCollection.

@Test
public void queryCollection() {
    String queryMapKey = mapKeyPrefix + 2;
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(args.set);
    stmt.setBinNames(binName);
    stmt.setFilter(Filter.contains(binName, IndexCollectionType.MAPKEYS, queryMapKey));
    RecordSet rs = client.query(null, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            Record record = rs.getRecord();
            Map<?, ?> result = (Map<?, ?>) record.getValue(binName);
            if (!result.containsKey(queryMapKey)) {
                fail("Query mismatch: Expected mapKey " + queryMapKey + " Received " + result);
            }
            count++;
        }
        assertNotEquals(0, count);
    } finally {
        rs.close();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) Record(com.aerospike.client.Record) RecordSet(com.aerospike.client.query.RecordSet) HashMap(java.util.HashMap) Map(java.util.Map) 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