Search in sources :

Example 26 with RecordSet

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

the class TestQueryFilterSet method queryTTL.

@Test
public void queryTTL() {
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(set1);
    QueryPolicy policy = new QueryPolicy();
    policy.filterExp = Exp.build(Exp.le(Exp.ttl(), Exp.val(60)));
    RecordSet rs = client.query(policy, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            count++;
        }
        assertEquals(1, count);
    } finally {
        rs.close();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) RecordSet(com.aerospike.client.query.RecordSet) QueryPolicy(com.aerospike.client.policy.QueryPolicy) Test(org.junit.Test)

Example 27 with RecordSet

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

the class TestQueryRPS method scan.

@Test
public void scan() {
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(args.set);
    stmt.setRecordsPerSecond(rps);
    RecordSet rs = client.query(null, stmt);
    drainRecords(rs);
    for (Node n : client.getNodes()) {
        checkRuntime(n, stmt);
    }
}
Also used : Statement(com.aerospike.client.query.Statement) Node(com.aerospike.client.cluster.Node) RecordSet(com.aerospike.client.query.RecordSet) Test(org.junit.Test)

Example 28 with RecordSet

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

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

Example 30 with RecordSet

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

the class QueryRegion method runQuery.

private void runQuery(AerospikeClient client, Parameters params, String indexName, String binName) throws Exception {
    StringBuilder rgnsb = new StringBuilder();
    rgnsb.append("{ ");
    rgnsb.append("    \"type\": \"Polygon\", ");
    rgnsb.append("    \"coordinates\": [ ");
    rgnsb.append("        [[-122.500000, 37.000000],[-121.000000, 37.000000], ");
    rgnsb.append("         [-121.000000, 38.080000],[-122.500000, 38.080000], ");
    rgnsb.append("         [-122.500000, 37.000000]] ");
    rgnsb.append("    ] ");
    rgnsb.append(" } ");
    console.info("QueryRegion for: ns=%s set=%s index=%s bin=%s within %s", params.namespace, params.set, indexName, binName, rgnsb);
    Statement stmt = new Statement();
    stmt.setNamespace(params.namespace);
    stmt.setSetName(params.set);
    stmt.setBinNames(binName);
    stmt.setFilter(Filter.geoWithinRegion(binName, rgnsb.toString()));
    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 != 6) {
            console.error("Query count mismatch. Expected 6. 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

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