/** * Execute query, apply statement's aggregation function, and return result iterator. The query * executor puts results on a queue in separate threads. The calling thread concurrently pops * results off the queue through the result iterator. * <p> * The aggregation function is called on both server and client (final reduce). Therefore, * the Lua script files must also reside on both server and client. * The package name is used to locate the udf file location: * <p> * udf file = <udf dir>/<package name>.lua * * @param policy generic configuration parameters, pass in null for defaults * @param statement database query command * @param packageName server package where user defined function resides * @param functionName aggregation function name * @param functionArgs arguments to pass to function name, if any * @return result iterator * @throws AerospikeException if query fails */ public final ResultSet queryAggregate( QueryPolicy policy, Statement statement, String packageName, String functionName, Value... functionArgs ) throws AerospikeException { statement.setAggregateFunction(packageName, functionName, functionArgs); return queryAggregate(policy, statement); }
private KeyRecordIterator queryByLua(Statement stmt, Boolean metaOnly, Node node, Qualifier[] qualifiers){ Map<String, Object> originArgs = new HashMap<String, Object>(); originArgs.put("includeAllFields", 1); ResultSet resultSet = null; String filterFuncStr = buildFilterFunction(qualifiers); originArgs.put("filterFuncStr", filterFuncStr); if (metaOnly) stmt.setAggregateFunction(this.getClass().getClassLoader(), AS_UTILITY_PATH, QUERY_MODULE, "query_meta", Value.get(originArgs)); else stmt.setAggregateFunction(this.getClass().getClassLoader(), AS_UTILITY_PATH, QUERY_MODULE, "select_records", Value.get(originArgs)); if (node != null) { resultSet = this.client.queryAggregateNode(queryPolicy, stmt, node); } else { resultSet = this.client.queryAggregate(queryPolicy, stmt); } return new KeyRecordIterator(stmt.getNamespace(), resultSet); }
/** * Execute query, apply statement's aggregation function, and return result iterator. The query * executor puts results on a queue in separate threads. The calling thread concurrently pops * results off the queue through the result iterator. * <p> * The aggregation function is called on both server and client (final reduce). Therefore, * the Lua script files must also reside on both server and client. * The package name is used to locate the udf file location: * <p> * udf file = <udf dir>/<package name>.lua * * @param policy generic configuration parameters, pass in null for defaults * @param statement database query command * @param packageName server package where user defined function resides * @param functionName aggregation function name * @param functionArgs arguments to pass to function name, if any * @return result iterator * @throws AerospikeException if query fails */ public final ResultSet queryAggregate( QueryPolicy policy, Statement statement, String packageName, String functionName, Value... functionArgs ) throws AerospikeException { statement.setAggregateFunction(packageName, functionName, functionArgs); return queryAggregate(policy, statement); }
@SuppressWarnings("unchecked") @Override public <T> Iterable<T> aggregate(Filter filter, Class<T> outputType, String module, String function, List<Value> arguments) { Assert.notNull(outputType, "Output type must not be null!"); AerospikePersistentEntity<?> entity = mappingContext .getPersistentEntity(outputType); Statement statement = new Statement(); if (filter != null) statement.setFilters(filter); statement.setSetName(entity.getSetName()); statement.setNamespace(this.namespace); ResultSet resultSet = null; if (arguments != null && arguments.size() > 0) resultSet = this.client.queryAggregate(null, statement, module, function, arguments.toArray(new Value[0])); else resultSet = this.client.queryAggregate(null, statement); return (Iterable<T>) resultSet; }
/** * Select records filtered by Qualifiers * * @param stmt A Statement object containing Namespace, Set and the Bins to be returned. * @param sortMap <STRONG>NOT IMPLEMENTED</STRONG> * @param qualifiers Zero or more Qualifiers for the update query * @return A KeyRecordIterator to iterate over the results */ public KeyRecordIterator select(Statement stmt, Map<String, String> sortMap, Qualifier... qualifiers) { KeyRecordIterator results = null; if (qualifiers != null && qualifiers.length > 0) { Map<String, Object> originArgs = new HashMap<String, Object>(); originArgs.put("includeAllFields", 1); String filterFuncStr = buildFilterFunction(qualifiers); originArgs.put("filterFuncStr", filterFuncStr); String sortFuncStr = buildSortFunction(sortMap); originArgs.put("sortFuncStr", sortFuncStr); stmt.setAggregateFunction(this.getClass().getClassLoader(), AS_UTILITY_PATH, QUERY_MODULE, "select_records", Value.get(originArgs)); ResultSet resultSet = this.client.queryAggregate(queryPolicy, stmt); results = new KeyRecordIterator(stmt.getNamespace(), resultSet); } else { RecordSet recordSet = this.client.query(queryPolicy, stmt); results = new KeyRecordIterator(stmt.getNamespace(), recordSet); } return results; }
stmt.setAggregateFunction("geo_filter_example", "match_amenity", Value.get(amenStr)); ResultSet rs = client.queryAggregate(null, stmt);
stmt.setAggregateFunction("average_example", "average"); ResultSet rs = client.queryAggregate(null, stmt);
ResultSet rs = client.queryAggregate(null, stmt);
ResultSet rs = client.queryAggregate(null, stmt);