/** * Get an aggregator using the default set of tags for the final result. The tags will * be extracted based on the exact matches for the underlying query. */ default Aggregator aggregator() { return aggregator(query().exactTags(), true); }
private Iterable<TagsValuePair> evalNoCheck(DataExpr expr, Iterable<TagsValuePair> input) { DataExpr.Aggregator aggr = expr.aggregator(expr.query().exactTags(), false); for (TagsValuePair p : input) { aggr.update(p); } return aggr.result(); }
@Override public void update(TagsValuePair p) { Map<String, String> tags = p.tags(); if (!shouldCheckQuery || af.query().matches(tags)) { Map<String, String> k = keyTags(tags); if (k != null) { k.putAll(queryTags); aggrs.computeIfAbsent(k, ks -> af.aggregator(ks, false)).update(p); } } }
@Override public void update(TagsValuePair p) { Map<String, String> tags = p.tags(); if (!shouldCheckQuery || query.matches(tags)) { pairs.add(new TagsValuePair(tags, p.value())); } }
/** * Evaluate the data expression over the input. * * @param input * Set of data values. The data will get filtered based on the query, that does * not need to be done in advance. * @return * Aggregated data values. */ default Iterable<TagsValuePair> eval(Iterable<TagsValuePair> input) { Aggregator aggr = aggregator(); for (TagsValuePair p : input) { aggr.update(p); } return aggr.result(); }
private Subscription sub(int i) { return new Subscription() .withId("" + i) .withExpression("name," + i + ",:eq,:sum") .withFrequency(60000); }
/** * Check to see if this query matches an id. Equivalent to calling {@link #matches(Map)} * with the result of {@link #toMap(Id)}. * * @param id * Id to use when checking for a match. * @return * True if the query expression matches the id. */ default boolean matches(Id id) { return matches(toMap(id)); }
/** Set the expression for the subscription. */ public void setExpression(String expression) { this.expression = expression; this.expr = Parser.parseDataExpr(expression); }
/** Set the available subscriptions. */ public Subscriptions withExpressions(List<Subscription> expressions) { setExpressions(expressions); return this; }
/** Set the expression for the subscription. */ public Subscription withExpression(String expression) { setExpression(expression); return this; }
@Override public int hashCode() { int result = hashCodeOrZero(id); result = 31 * result + hashCodeOrZero(expression); result = 31 * result + (int) (frequency ^ (frequency >>> 32)); result = 31 * result + hashCodeOrZero(expr); return result; }
/** Returns a new query: {@code this AND q}. */ default Query and(Query q) { return new And(this, q); }
/** Returns a new query: {@code this OR q}. */ default Query or(Query q) { return new Or(this, q); }
/** Returns an inverted version of this query. */ default Query not() { return new Not(this); }
@Override public Query query() { return af.query(); }
@Override public void update(TagsValuePair p) { Map<String, String> tags = new HashMap<>(p.tags()); if (!shouldCheckQuery || af.query().matches(tags)) { for (String k : keys) { tags.remove(k); } aggrs.computeIfAbsent(tags, ks -> af.aggregator(ks, false)).update(p); } }