Search in sources :

Example 41 with RecordSet

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

the class TestQueryPredExp method queryPredicate8.

@Test
public void queryPredicate8() {
    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("D"), PredExp.stringUnequal(), PredExp.mapBin("mapbin"), PredExp.mapKeyIterateAnd("x"));
    /*
		stmt.setPredicate(
			Predicate.mapKeyExclude("mapbin", "x", Predicate.var("x").equal("D"))
			);
		*/
    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)

Example 42 with RecordSet

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

the class AerospikeTestUtils method cleanMetaTable.

// removes all records from set AerospikeTransactionalStore.DEFAULT_META_SET (used to store
// committed window ids) in namespace NAMESPACE
// 
static void cleanMetaTable() {
    AerospikeClient client = null;
    try {
        client = new AerospikeClient(NODE, PORT);
        Statement stmnt = new Statement();
        stmnt.setNamespace(NAMESPACE);
        stmnt.setSetName(AerospikeTransactionalStore.DEFAULT_META_SET);
        RecordSet rs = client.query(null, stmnt);
        while (rs.next()) {
            client.delete(null, rs.getKey());
        }
    } catch (AerospikeException e) {
        LOG.error("cleanMetaTable failed: {}", e);
        throw e;
    } finally {
        if (null != client) {
            client.close();
        }
    }
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) AerospikeException(com.aerospike.client.AerospikeException) Statement(com.aerospike.client.query.Statement) RecordSet(com.aerospike.client.query.RecordSet)

Example 43 with RecordSet

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

the class AerospikeTestUtils method getNumOfEventsInStore.

// returns the number of records in set SET_NAME in namespace NAMESPACE
static long getNumOfEventsInStore() {
    AerospikeClient client = null;
    try {
        long count = 0;
        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()) {
            count++;
        }
        return count;
    } catch (AerospikeException e) {
        LOG.error("getNumOfEventsInStore failed: {}", e);
        throw e;
    } finally {
        if (null != client) {
            client.close();
        }
    }
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) AerospikeException(com.aerospike.client.AerospikeException) Statement(com.aerospike.client.query.Statement) RecordSet(com.aerospike.client.query.RecordSet)

Example 44 with RecordSet

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

the class AerospikeTestUtils method cleanTable.

// removes all records from set SET_NAME in namespace NAMESPACE
static void cleanTable() {
    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()) {
            client.delete(null, rs.getKey());
        }
    } catch (AerospikeException e) {
        LOG.error("cleanTable failed: {}", e);
        throw e;
    } finally {
        if (null != client) {
            client.close();
        }
    }
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) AerospikeException(com.aerospike.client.AerospikeException) Statement(com.aerospike.client.query.Statement) RecordSet(com.aerospike.client.query.RecordSet)

Example 45 with RecordSet

use of com.aerospike.client.query.RecordSet in project gora by apache.

the class AerospikeStore method execute.

/**
 * {@inheritDoc}
 *
 * @param query the query to execute.
 * @return the query result
 */
@Override
public Result<K, T> execute(Query<K, T> query) throws GoraException {
    List<AerospikeResultRecord> resultRecords = new ArrayList<>();
    String namespace = aerospikeParameters.getAerospikeMapping().getNamespace();
    String set = aerospikeParameters.getAerospikeMapping().getSet();
    try {
        // Query execution without any keys
        if (query.getStartKey() == null && query.getEndKey() == null) {
            try (RecordSet recordSet = aerospikeClient.query(null, getStatement(namespace, set))) {
                while (recordSet.next()) {
                    AerospikeResultRecord aerospikeRecord = new AerospikeResultRecord(recordSet.getKey(), recordSet.getRecord());
                    resultRecords.add(aerospikeRecord);
                }
            }
        } else // Query execution for single key
        if (query.getKey() != null) {
            Key key = getAerospikeKey(query.getKey());
            Record record = aerospikeClient.get(null, key);
            if (record != null) {
                resultRecords.add(new AerospikeResultRecord(key, record));
            }
        }
        // }
        return new AerospikeQueryResult<>(this, query, resultRecords, getFieldsToQuery(null));
    } catch (Exception e) {
        throw new GoraException(e);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) AerospikeResultRecord(org.apache.gora.aerospike.query.AerospikeResultRecord) ArrayList(java.util.ArrayList) Record(com.aerospike.client.Record) AerospikeResultRecord(org.apache.gora.aerospike.query.AerospikeResultRecord) RecordSet(com.aerospike.client.query.RecordSet) AerospikeQueryResult(org.apache.gora.aerospike.query.AerospikeQueryResult) Key(com.aerospike.client.Key) AerospikeException(com.aerospike.client.AerospikeException) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException)

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