Search in sources :

Example 1 with TSSubQuery

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;
}
Also used : TSQuery(net.opentsdb.core.TSQuery) ArrayList(java.util.ArrayList) TSSubQuery(net.opentsdb.core.TSSubQuery)

Example 2 with TSSubQuery

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++;
    }
}
Also used : Query(net.opentsdb.core.Query) TSQuery(net.opentsdb.core.TSQuery) TSSubQuery(net.opentsdb.core.TSSubQuery) DataPoints(net.opentsdb.core.DataPoints) TSSubQuery(net.opentsdb.core.TSSubQuery) TSQuery(net.opentsdb.core.TSQuery) Pair(net.opentsdb.utils.Pair)

Example 3 with TSSubQuery

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TSSubQuery(net.opentsdb.core.TSSubQuery)

Example 4 with TSSubQuery

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);
}
Also used : TagVFilter(net.opentsdb.query.filter.TagVFilter) ArrayList(java.util.ArrayList) TSSubQuery(net.opentsdb.core.TSSubQuery) IncomingDataPoint(net.opentsdb.core.IncomingDataPoint)

Example 5 with TSSubQuery

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);
}
Also used : ArrayList(java.util.ArrayList) TSSubQuery(net.opentsdb.core.TSSubQuery) IncomingDataPoint(net.opentsdb.core.IncomingDataPoint)

Aggregations

TSSubQuery (net.opentsdb.core.TSSubQuery)41 TSQuery (net.opentsdb.core.TSQuery)34 Test (org.junit.Test)28 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)28 ArrayList (java.util.ArrayList)11 TagVWildcardFilter (net.opentsdb.query.filter.TagVWildcardFilter)7 Callback (com.stumbleupon.async.Callback)4 Deferred (com.stumbleupon.async.Deferred)4 HashMap (java.util.HashMap)4 DataPoints (net.opentsdb.core.DataPoints)4 IOException (java.io.IOException)3 DataPoint (net.opentsdb.core.DataPoint)3 IncomingDataPoint (net.opentsdb.core.IncomingDataPoint)3 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2 OutputStream (java.io.OutputStream)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 Query (net.opentsdb.core.Query)2 ExpressionIterator (net.opentsdb.query.expression.ExpressionIterator)2