Search in sources :

Example 6 with ResultSet

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

the class QueryFilter method runQuery.

@SuppressWarnings("unchecked")
private void runQuery(AerospikeClient client, Parameters params, String indexName, String binName) throws Exception {
    String nameFilter = "Bill";
    String passFilter = "hknfpkj";
    console.info("Query for: ns=%s set=%s index=%s name=%s pass=%s", params.namespace, params.set, indexName, nameFilter, passFilter);
    Statement stmt = new Statement();
    stmt.setNamespace(params.namespace);
    stmt.setSetName(params.set);
    stmt.setFilter(Filter.equal(binName, nameFilter));
    stmt.setAggregateFunction("filter_example", "profile_filter", Value.get(passFilter));
    // passFilter will be applied in filter_example.lua.
    ResultSet rs = client.queryAggregate(null, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            Map<String, Object> map = (Map<String, Object>) rs.getObject();
            validate(map, "name", nameFilter);
            validate(map, "password", passFilter);
            count++;
        }
        if (count == 0) {
            console.error("Query failed. No records returned.");
        }
    } finally {
        rs.close();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) ResultSet(com.aerospike.client.query.ResultSet) Map(java.util.Map)

Example 7 with ResultSet

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

the class QueryRegionFilter method runQuery.

private void runQuery(AerospikeClient client, Parameters params, String indexName, String binName1, String binName2) 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("Query for: ns=%s set=%s index=%s bin1=%s bin2=%s within %s", params.namespace, params.set, indexName, binName1, binName2, rgnsb);
    String amenStr = "school";
    Statement stmt = new Statement();
    stmt.setNamespace(params.namespace);
    stmt.setSetName(params.set);
    stmt.setFilter(Filter.geoWithinRegion(binName1, rgnsb.toString()));
    stmt.setAggregateFunction("geo_filter_example", "match_amenity", Value.get(amenStr));
    ResultSet rs = client.queryAggregate(null, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            Object result = rs.getObject();
            console.info("Record found: value2=%s", result);
            count++;
        }
        if (count != 2) {
            console.error("wrong number of schools found. %d != 2", count);
        }
    } finally {
        rs.close();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) ResultSet(com.aerospike.client.query.ResultSet)

Aggregations

ResultSet (com.aerospike.client.query.ResultSet)7 Statement (com.aerospike.client.query.Statement)7 Map (java.util.Map)4 Test (org.junit.Test)3