Search in sources :

Example 6 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 {@linke #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 7 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 8 with TSSubQuery

use of net.opentsdb.core.TSSubQuery in project opentsdb by OpenTSDB.

the class TestQueryRpc method parseQueryMTypeWGroupByWildcardExplicit.

@Test
public void parseQueryMTypeWGroupByWildcardExplicit() throws Exception {
    HttpQuery query = NettyMocks.getQuery(tsdb, "/api/query?start=1h-ago&m=sum:sys.cpu.0{host=" + TagVWildcardFilter.FILTER_NAME + "(*quirm)}");
    TSQuery tsq = (TSQuery) parseQuery.invoke(rpc, tsdb, query, expressions);
    TSSubQuery sub = tsq.getQueries().get(0);
    sub.validateAndSetQuery();
    assertEquals(1, sub.getFilters().size());
    assertTrue(sub.getFilters().get(0) instanceof TagVWildcardFilter);
}
Also used : TSQuery(net.opentsdb.core.TSQuery) TagVWildcardFilter(net.opentsdb.query.filter.TagVWildcardFilter) TSSubQuery(net.opentsdb.core.TSSubQuery) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with TSSubQuery

use of net.opentsdb.core.TSSubQuery in project opentsdb by OpenTSDB.

the class TestQueryRpc method parseQueryMTypeWEmptyFilterBrackets.

@Test
public void parseQueryMTypeWEmptyFilterBrackets() throws Exception {
    HttpQuery query = NettyMocks.getQuery(tsdb, "/api/query?start=1h-ago&m=sum:sys.cpu.0{}{}");
    TSQuery tsq = (TSQuery) parseQuery.invoke(rpc, tsdb, query, expressions);
    TSSubQuery sub = tsq.getQueries().get(0);
    sub.validateAndSetQuery();
    assertEquals(0, sub.getFilters().size());
}
Also used : TSQuery(net.opentsdb.core.TSQuery) TSSubQuery(net.opentsdb.core.TSSubQuery) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with TSSubQuery

use of net.opentsdb.core.TSSubQuery in project opentsdb by OpenTSDB.

the class TestQueryRpc method parseQueryMTypeWGroupByAndWildcardFilterSameTagK.

@Test
public void parseQueryMTypeWGroupByAndWildcardFilterSameTagK() throws Exception {
    HttpQuery query = NettyMocks.getQuery(tsdb, "/api/query?start=1h-ago&m=sum:sys.cpu.0{host=quirm|tsort}" + "{host=wildcard(*quirm)}");
    TSQuery tsq = (TSQuery) parseQuery.invoke(rpc, tsdb, query, expressions);
    TSSubQuery sub = tsq.getQueries().get(0);
    sub.validateAndSetQuery();
    assertTrue(sub.getFilters().get(0) instanceof TagVWildcardFilter);
    assertTrue(sub.getFilters().get(1) instanceof TagVLiteralOrFilter);
}
Also used : TSQuery(net.opentsdb.core.TSQuery) TagVWildcardFilter(net.opentsdb.query.filter.TagVWildcardFilter) TSSubQuery(net.opentsdb.core.TSSubQuery) TagVLiteralOrFilter(net.opentsdb.query.filter.TagVLiteralOrFilter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

TSSubQuery (net.opentsdb.core.TSSubQuery)37 TSQuery (net.opentsdb.core.TSQuery)30 Test (org.junit.Test)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)26 ArrayList (java.util.ArrayList)10 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 Map (java.util.Map)2 Query (net.opentsdb.core.Query)2 ExpressionIterator (net.opentsdb.query.expression.ExpressionIterator)2 TimeSyncedIterator (net.opentsdb.query.expression.TimeSyncedIterator)2