Search in sources :

Example 41 with Record

use of com.aerospike.client.Record in project aerospike-client-java by aerospike.

the class PutGet method runSingleBinTest.

/**
 * Execute put and get on a server configured as single-bin.
 */
private void runSingleBinTest(AerospikeClient client, Parameters params) throws Exception {
    Key key = new Key(params.namespace, params.set, "putgetkey");
    Bin bin = new Bin("", "value");
    console.info("Single Bin Put: namespace=%s set=%s key=%s value=%s", key.namespace, key.setName, key.userKey, bin.value);
    client.put(params.writePolicy, key, bin);
    console.info("Single Bin Get: namespace=%s set=%s key=%s", key.namespace, key.setName, key.userKey);
    Record record = client.get(params.policy, key);
    if (record == null) {
        throw new Exception(String.format("Failed to get: namespace=%s set=%s key=%s", key.namespace, key.setName, key.userKey));
    }
    validateBin(key, bin, record);
}
Also used : Bin(com.aerospike.client.Bin) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key)

Example 42 with Record

use of com.aerospike.client.Record in project aerospike-client-java by aerospike.

the class QueryCollection method runQuery.

private void runQuery(AerospikeClient client, Parameters params, String indexName, String binName, String queryMapKey) throws Exception {
    console.info("Query for: ns=%s set=%s index=%s bin=%s mapkey contains=%s", params.namespace, params.set, indexName, binName, queryMapKey);
    Statement stmt = new Statement();
    stmt.setNamespace(params.namespace);
    stmt.setSetName(params.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()) {
            // Key key = rs.getKey();
            Record record = rs.getRecord();
            Map<?, ?> result = (Map<?, ?>) record.getValue(binName);
            if (result.containsKey(queryMapKey)) {
            /*console.info("Record found: ns=%s set=%s bin=%s key=%s value=%s",
						key.namespace, key.setName, binName, Buffer.bytesToHexString(key.digest), result);
					*/
            } else {
                console.error("Query mismatch: Expected mapKey %s. Received %s.", queryMapKey, result);
            }
            count++;
        }
        if (count == 0) {
            console.error("Query failed. No records returned.");
        } else {
            console.info("Number of records %d", 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)

Example 43 with Record

use of com.aerospike.client.Record in project aerospike-client-java by aerospike.

the class QueryGeoCollection method runQuery.

private void runQuery(AerospikeClient client, Parameters params, String binName, String binName2, IndexCollectionType indexType) throws Exception {
    console.info("Query for: ns=%s set=%s bin=%s %s within <region>", params.namespace, params.set, binName, indexType.toString());
    StringBuilder rgnsb = generateQueryRegion();
    Statement stmt = new Statement();
    stmt.setNamespace(params.namespace);
    stmt.setSetName(params.set);
    stmt.setFilter(Filter.geoWithinRegion(binName, indexType, rgnsb.toString()));
    RecordSet rs = client.query(null, stmt);
    try {
        int count = 0;
        Set<String> uniques = new HashSet<String>();
        while (rs.next()) {
            Record record = rs.getRecord();
            uniques.add(record.getString(binName2));
            count++;
        }
        if (count != 697) {
            console.error("Query failed. %d records expected. %d returned.", 697, count);
        } else if (uniques.size() != 21) {
            console.error("Query failed. %d unique records expected. %d unique returned.", 21, uniques.size());
        } else {
            console.info("query succeeded with %d records %d unique", count, uniques.size());
        }
    } finally {
        rs.close();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) Record(com.aerospike.client.Record) RecordSet(com.aerospike.client.query.RecordSet) HashSet(java.util.HashSet)

Example 44 with Record

use of com.aerospike.client.Record in project aerospike-client-java by aerospike.

the class TestAdd method add.

@Test
public void add() {
    Key key = new Key(args.namespace, args.set, "addkey");
    String binName = args.getBinName("addbin");
    // Delete record if it already exists.
    client.delete(null, key);
    // Perform some adds and check results.
    Bin bin = new Bin(binName, 10);
    client.add(null, key, bin);
    bin = new Bin(binName, 5);
    client.add(null, key, bin);
    Record record = client.get(null, key, bin.name);
    assertBinEqual(key, record, bin.name, 15);
    // Test add and get combined.
    bin = new Bin(binName, 30);
    record = client.operate(null, key, Operation.add(bin), Operation.get(bin.name));
    assertBinEqual(key, record, bin.name, 45);
}
Also used : Bin(com.aerospike.client.Bin) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 45 with Record

use of com.aerospike.client.Record in project aerospike-client-java by aerospike.

the class QueryRegion method runRadiusQuery.

private void runRadiusQuery(AerospikeClient client, Parameters params, String indexName, String binName) throws Exception {
    double lon = -122.0;
    double lat = 37.5;
    double radius = 50000.0;
    console.info("QueryRadius for: ns=%s set=%s index=%s bin=%s within long=%f lat=%f radius=%f", params.namespace, params.set, indexName, binName, lon, lat, radius);
    Statement stmt = new Statement();
    stmt.setNamespace(params.namespace);
    stmt.setSetName(params.set);
    stmt.setBinNames(binName);
    stmt.setFilter(Filter.geoWithinRadius(binName, lon, lat, radius));
    RecordSet rs = client.query(null, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            Key key = rs.getKey();
            Record record = rs.getRecord();
            String result = record.getGeoJSONString(binName);
            console.info("Record found: ns=%s set=%s bin=%s digest=%s value=%s", key.namespace, key.setName, binName, Buffer.bytesToHexString(key.digest), result);
            count++;
        }
        if (count != 4) {
            console.error("Query count mismatch. Expected 4. Received " + count);
        }
    } finally {
        rs.close();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) Record(com.aerospike.client.Record) RecordSet(com.aerospike.client.query.RecordSet) Key(com.aerospike.client.Key)

Aggregations

Record (com.aerospike.client.Record)259 Key (com.aerospike.client.Key)140 Test (org.junit.Test)139 ArrayList (java.util.ArrayList)75 Bin (com.aerospike.client.Bin)70 AerospikeException (com.aerospike.client.AerospikeException)62 Value (com.aerospike.client.Value)54 WritePolicy (com.aerospike.client.policy.WritePolicy)47 List (java.util.List)41 HashMap (java.util.HashMap)36 ThrowingRunnable (org.junit.function.ThrowingRunnable)32 BatchPolicy (com.aerospike.client.policy.BatchPolicy)29 Policy (com.aerospike.client.policy.Policy)29 Statement (com.aerospike.client.query.Statement)23 RecordSet (com.aerospike.client.query.RecordSet)22 Expression (com.aerospike.client.exp.Expression)18 Map (java.util.Map)15 HLLValue (com.aerospike.client.Value.HLLValue)14 Collections.singletonList (java.util.Collections.singletonList)9 MapPolicy (com.aerospike.client.cdt.MapPolicy)7