use of net.opentsdb.core.TSSubQuery in project opentsdb by OpenTSDB.
the class TestHttpJsonSerializer method getTestQuery.
/**
* @return Returns a test TSQuery object to pass on to the serializer
*/
private TSQuery getTestQuery(final boolean show_stats, final boolean show_summary) {
final TSQuery data_query = new TSQuery();
data_query.setStart("1356998400");
data_query.setEnd("1388534400");
data_query.setShowStats(show_stats);
data_query.setShowSummary(show_summary);
final TSSubQuery sub_query = new TSSubQuery();
sub_query.setMetric("sys.cpu.user");
sub_query.setAggregator("sum");
final ArrayList<TSSubQuery> sub_queries = new ArrayList<TSSubQuery>(1);
sub_queries.add(sub_query);
data_query.setQueries(sub_queries);
return data_query;
}
use of net.opentsdb.core.TSSubQuery in project opentsdb by OpenTSDB.
the class BaseTimeSyncedIteratorTest method runQueries.
/**
* Executes the queries against MockBase through the regular pipeline and stores
* the results in {@link #results}
* @param subs The queries to execute
*/
protected void runQueries(final ArrayList<TSSubQuery> subs) throws Exception {
query = new TSQuery();
query.setStart(Long.toString(START_TS));
query.setQueries(subs);
query.validateAndSetQuery();
final Query[] compiled = query.buildQueries(tsdb);
results = new HashMap<String, Pair<TSSubQuery, DataPoints[]>>(compiled.length);
iterators = new HashMap<String, ITimeSyncedIterator>(compiled.length);
int index = 0;
for (final Query q : compiled) {
final DataPoints[] dps = q.runAsync().join();
results.put(Integer.toString(index), new Pair<TSSubQuery, DataPoints[]>(query.getQueries().get(index), dps));
final ITimeSyncedIterator it = new TimeSyncedIterator(Integer.toString(index), query.getQueries().get(index).getFilterTagKs(), dps);
it.setFillPolicy(new NumericFillPolicy(FillPolicy.NOT_A_NUMBER));
iterators.put(Integer.toString(index), it);
index++;
}
}
use of net.opentsdb.core.TSSubQuery in project opentsdb by OpenTSDB.
the class BaseTimeSyncedIteratorTest method queryAB_Dstar.
/**
* Queries for metrics A and B with a group by all on the D tag
*/
protected void queryAB_Dstar() throws Exception {
final ArrayList<TSSubQuery> subs = new ArrayList<TSSubQuery>(2);
TSSubQuery sub = new TSSubQuery();
HashMap<String, String> query_tags = new HashMap<String, String>(1);
query_tags.put("D", "*");
sub = new TSSubQuery();
sub.setMetric("A");
sub.setTags(query_tags);
sub.setAggregator("sum");
subs.add(sub);
sub = new TSSubQuery();
sub.setMetric("B");
query_tags = new HashMap<String, String>(1);
query_tags.put("D", "*");
sub.setTags(query_tags);
sub.setAggregator("sum");
subs.add(sub);
runQueries(subs);
}
use of net.opentsdb.core.TSSubQuery in project opentsdb by OpenTSDB.
the class QueryRpc method parseMTypeSubQuery.
/**
* Parses a query string "m=..." type query and adds it to the TSQuery.
* This will generate a TSSubQuery and add it to the TSQuery if successful
* @param query_string The value of the m query string parameter, i.e. what
* comes after the equals sign
* @param data_query The query we're building
* @throws BadRequestException if we are unable to parse the query or it is
* missing components
*/
private static void parseMTypeSubQuery(final String query_string, TSQuery data_query) {
if (query_string == null || query_string.isEmpty()) {
throw new BadRequestException("The query string was empty");
}
// m is of the following forms:
// agg:[interval-agg:][rate:]metric[{tag=value,...}]
// where the parts in square brackets `[' .. `]' are optional.
final String[] parts = Tags.splitString(query_string, ':');
int i = parts.length;
if (i < 2 || i > 5) {
throw new BadRequestException("Invalid parameter m=" + query_string + " (" + (i < 2 ? "not enough" : "too many") + " :-separated parts)");
}
final TSSubQuery sub_query = new TSSubQuery();
// the aggregator is first
sub_query.setAggregator(parts[0]);
// Move to the last part (the metric name).
i--;
List<TagVFilter> filters = new ArrayList<TagVFilter>();
sub_query.setMetric(Tags.parseWithMetricAndFilters(parts[i], filters));
sub_query.setFilters(filters);
// parse out the rate and downsampler
for (int x = 1; x < parts.length - 1; x++) {
if (parts[x].toLowerCase().startsWith("rate")) {
sub_query.setRate(true);
if (parts[x].indexOf("{") >= 0) {
sub_query.setRateOptions(QueryRpc.parseRateOptions(true, parts[x]));
}
} else if (Character.isDigit(parts[x].charAt(0))) {
sub_query.setDownsample(parts[x]);
} else if (parts[x].equalsIgnoreCase("pre-agg")) {
sub_query.setPreAggregate(true);
} else if (parts[x].toLowerCase().startsWith("rollup_")) {
sub_query.setRollupUsage(parts[x]);
} else if (parts[x].toLowerCase().startsWith("percentiles")) {
sub_query.setPercentiles(QueryRpc.parsePercentiles(parts[x]));
} else if (parts[x].toLowerCase().startsWith("show-histogram-buckets")) {
sub_query.setShowHistogramBuckets(true);
} else if (parts[x].toLowerCase().startsWith("explicit_tags")) {
sub_query.setExplicitTags(true);
}
}
if (data_query.getQueries() == null) {
final ArrayList<TSSubQuery> subs = new ArrayList<TSSubQuery>(1);
data_query.setQueries(subs);
}
data_query.getQueries().add(sub_query);
}
use of net.opentsdb.core.TSSubQuery in project opentsdb by OpenTSDB.
the class QueryRpc method parseTsuidTypeSubQuery.
/**
* Parses a "tsuid=..." type query and adds it to the TSQuery.
* This will generate a TSSubQuery and add it to the TSQuery if successful
* @param query_string The value of the m query string parameter, i.e. what
* comes after the equals sign
* @param data_query The query we're building
* @throws BadRequestException if we are unable to parse the query or it is
* missing components
*/
private static void parseTsuidTypeSubQuery(final String query_string, TSQuery data_query) {
if (query_string == null || query_string.isEmpty()) {
throw new BadRequestException("The tsuid query string was empty");
}
// tsuid queries are of the following forms:
// agg:[interval-agg:][rate:]tsuid[,s]
// where the parts in square brackets `[' .. `]' are optional.
final String[] parts = Tags.splitString(query_string, ':');
int i = parts.length;
if (i < 2 || i > 5) {
throw new BadRequestException("Invalid parameter m=" + query_string + " (" + (i < 2 ? "not enough" : "too many") + " :-separated parts)");
}
final TSSubQuery sub_query = new TSSubQuery();
// the aggregator is first
sub_query.setAggregator(parts[0]);
// Move to the last part (the metric name).
i--;
final List<String> tsuid_array = Arrays.asList(parts[i].split(","));
sub_query.setTsuids(tsuid_array);
// parse out the rate and downsampler
for (int x = 1; x < parts.length - 1; x++) {
if (parts[x].toLowerCase().startsWith("rate")) {
sub_query.setRate(true);
if (parts[x].indexOf("{") >= 0) {
sub_query.setRateOptions(QueryRpc.parseRateOptions(true, parts[x]));
}
} else if (Character.isDigit(parts[x].charAt(0))) {
sub_query.setDownsample(parts[x]);
} else if (parts[x].toLowerCase().startsWith("percentiles")) {
sub_query.setPercentiles(QueryRpc.parsePercentiles(parts[x]));
} else if (parts[x].toLowerCase().startsWith("show-histogram-buckets")) {
sub_query.setShowHistogramBuckets(true);
}
}
if (data_query.getQueries() == null) {
final ArrayList<TSSubQuery> subs = new ArrayList<TSSubQuery>(1);
data_query.setQueries(subs);
}
data_query.getQueries().add(sub_query);
}
Aggregations