Search in sources :

Example 6 with Query

use of net.opentsdb.query.pojo.Query in project opentsdb by OpenTSDB.

the class TestQueryExecutor method selfReferencingExpression.

@Test
public void selfReferencingExpression() throws Exception {
    oneExtraSameE();
    expressions = Arrays.asList(Expression.Builder().setId("e").setExpression("a + b").build(), Expression.Builder().setId("e2").setExpression("e * 2").build(), Expression.Builder().setId("e3").setExpression("e * 2").build(), Expression.Builder().setId("e4").setExpression("e2 + e4").build());
    final Query q = Query.Builder().setExpressions(expressions).setFilters(filters).setMetrics(metrics).setName("q1").setTime(time).build();
    final String json = JSON.serializeToString(q);
    final QueryRpc rpc = new QueryRpc();
    final HttpQuery query = NettyMocks.postQuery(tsdb, "/api/query/exp", json);
    // to the correct serializer
    query.getQueryBaseRoute();
    NettyMocks.mockChannelFuture(query);
    rpc.execute(tsdb, query);
    final String response = query.response().getContent().toString(Charset.forName("UTF-8"));
    assertTrue(response.contains("\"code\":400"));
    assertTrue(response.contains("\"message\":\"Self referencing"));
}
Also used : Query(net.opentsdb.query.pojo.Query) TSQuery(net.opentsdb.core.TSQuery) BaseTimeSyncedIteratorTest(net.opentsdb.query.expression.BaseTimeSyncedIteratorTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with Query

use of net.opentsdb.query.pojo.Query in project opentsdb by OpenTSDB.

the class TestQueryExecutor method circularReferenceExpression.

@Test
public void circularReferenceExpression() throws Exception {
    oneExtraSameE();
    expressions = Arrays.asList(Expression.Builder().setId("e").setExpression("a + e4").build(), Expression.Builder().setId("e2").setExpression("e * 2").build(), Expression.Builder().setId("e3").setExpression("e * 2").build(), Expression.Builder().setId("e4").setExpression("e2 + e3").build());
    final Query q = Query.Builder().setExpressions(expressions).setFilters(filters).setMetrics(metrics).setName("q1").setTime(time).build();
    final String json = JSON.serializeToString(q);
    final QueryRpc rpc = new QueryRpc();
    final HttpQuery query = NettyMocks.postQuery(tsdb, "/api/query/exp", json);
    // to the correct serializer
    query.getQueryBaseRoute();
    NettyMocks.mockChannelFuture(query);
    rpc.execute(tsdb, query);
    final String response = query.response().getContent().toString(Charset.forName("UTF-8"));
    assertTrue(response.contains("\"code\":400"));
    assertTrue(response.contains("\"message\":\"Circular reference found:"));
}
Also used : Query(net.opentsdb.query.pojo.Query) TSQuery(net.opentsdb.core.TSQuery) BaseTimeSyncedIteratorTest(net.opentsdb.query.expression.BaseTimeSyncedIteratorTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with Query

use of net.opentsdb.query.pojo.Query in project opentsdb by OpenTSDB.

the class TestQueryExecutor method noIntersectionsFoundNestedExpression.

@Test
public void noIntersectionsFoundNestedExpression() throws Exception {
    oneExtraSameE();
    final Metric metric1 = Metric.Builder().setMetric("A").setId("a").setFilter("f1").setAggregator("sum").build();
    final Metric metric2 = Metric.Builder().setMetric("B").setId("b").setFilter("f1").setAggregator("sum").build();
    final Metric metric3 = Metric.Builder().setMetric("D").setId("d").setFilter("f1").setAggregator("sum").build();
    metrics = Arrays.asList(metric1, metric2, metric3);
    expressions = Arrays.asList(Expression.Builder().setId("e").setExpression("a + b").setJoin(intersection).build(), Expression.Builder().setId("x").setExpression("d + e").setJoin(intersection).build());
    final Query q = Query.Builder().setExpressions(expressions).setFilters(filters).setMetrics(metrics).setName("q1").setTime(time).build();
    String json = JSON.serializeToString(q);
    final QueryRpc rpc = new QueryRpc();
    final HttpQuery query = NettyMocks.postQuery(tsdb, "/api/query/exp", json);
    // to the correct serializer
    query.getQueryBaseRoute();
    NettyMocks.mockChannelFuture(query);
    rpc.execute(tsdb, query);
    final String response = query.response().getContent().toString(Charset.forName("UTF-8"));
    assertTrue(response.contains("\"code\":400"));
    assertTrue(response.contains("\"message\":\"No intersections found"));
}
Also used : Query(net.opentsdb.query.pojo.Query) TSQuery(net.opentsdb.core.TSQuery) Metric(net.opentsdb.query.pojo.Metric) BaseTimeSyncedIteratorTest(net.opentsdb.query.expression.BaseTimeSyncedIteratorTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with Query

use of net.opentsdb.query.pojo.Query in project opentsdb by OpenTSDB.

the class TestQueryExecutor method twoExpressionsOneWithoutResultsDefaultOutput.

@Test
public void twoExpressionsOneWithoutResultsDefaultOutput() throws Exception {
    oneExtraSameE();
    final Metric metric1 = Metric.Builder().setMetric("A").setId("a").setFilter("f1").setAggregator("sum").build();
    final Metric metric2 = Metric.Builder().setMetric("B").setId("b").setFilter("f1").setAggregator("sum").build();
    final Metric metric3 = Metric.Builder().setMetric("D").setId("d").setFilter("f1").setAggregator("sum").build();
    final Metric metric4 = Metric.Builder().setMetric("F").setId("f").setFilter("f1").setAggregator("sum").build();
    metrics = Arrays.asList(metric1, metric2, metric3, metric4);
    expressions = Arrays.asList(Expression.Builder().setId("e").setExpression("a + b").setJoin(intersection).build(), Expression.Builder().setId("x").setExpression("d + f").setJoin(intersection).build());
    final Query q = Query.Builder().setExpressions(expressions).setFilters(filters).setMetrics(metrics).setName("q1").setTime(time).build();
    String json = JSON.serializeToString(q);
    final QueryRpc rpc = new QueryRpc();
    final HttpQuery query = NettyMocks.postQuery(tsdb, "/api/query/exp", json);
    // to the correct serializer
    query.getQueryBaseRoute();
    NettyMocks.mockChannelFuture(query);
    rpc.execute(tsdb, query);
    final String response = query.response().getContent().toString(Charset.forName("UTF-8"));
    assertTrue(response.contains("\"id\":\"e\""));
    assertTrue(response.contains("\"dps\":[[1431561600000,12.0,18.0]"));
    assertTrue(response.contains("[1431561660000,14.0,20.0]"));
    assertTrue(response.contains("[1431561720000,16.0,22.0]"));
    assertTrue(response.contains("\"firstTimestamp\":1431561600000"));
    assertTrue(response.contains("\"index\":1"));
    assertTrue(response.contains("\"metrics\":[\"A\",\"B\"]"));
    assertTrue(response.contains("\"index\":2"));
    assertTrue(response.contains("\"id\":\"x\""));
    assertTrue(response.contains("\"dps\":[]"));
    assertTrue(response.contains("\"firstTimestamp\":0"));
    assertTrue(response.contains("\"series\":0"));
}
Also used : Query(net.opentsdb.query.pojo.Query) TSQuery(net.opentsdb.core.TSQuery) Metric(net.opentsdb.query.pojo.Metric) BaseTimeSyncedIteratorTest(net.opentsdb.query.expression.BaseTimeSyncedIteratorTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with Query

use of net.opentsdb.query.pojo.Query in project opentsdb by OpenTSDB.

the class TestQueryExecutor method nestedExpressionsTwoLevelsDefaultOutput.

@Test
public void nestedExpressionsTwoLevelsDefaultOutput() throws Exception {
    oneExtraSameE();
    expressions = Arrays.asList(Expression.Builder().setId("e").setExpression("a + b").setJoin(intersection).build(), Expression.Builder().setId("e2").setExpression("e * 2").setJoin(intersection).build(), Expression.Builder().setId("e3").setExpression("e * 2").setJoin(intersection).build(), Expression.Builder().setId("e4").setExpression("e2 + e3").setJoin(intersection).build());
    final Query q = Query.Builder().setExpressions(expressions).setFilters(filters).setMetrics(metrics).setName("q1").setTime(time).build();
    final String json = JSON.serializeToString(q);
    final QueryRpc rpc = new QueryRpc();
    final HttpQuery query = NettyMocks.postQuery(tsdb, "/api/query/exp", json);
    NettyMocks.mockChannelFuture(query);
    rpc.execute(tsdb, query);
    final String response = query.response().getContent().toString(Charset.forName("UTF-8"));
    assertTrue(response.contains("\"id\":\"e\""));
    assertTrue(response.contains("\"dps\":[[1431561600000,12.0,18.0]"));
    assertTrue(response.contains("[1431561660000,14.0,20.0]"));
    assertTrue(response.contains("[1431561720000,16.0,22.0]"));
    assertTrue(response.contains("\"firstTimestamp\":1431561600000"));
    assertTrue(response.contains("\"index\":1"));
    assertTrue(response.contains("\"metrics\":[\"A\",\"B\"]"));
    assertTrue(response.contains("\"index\":2"));
    assertTrue(response.contains("\"id\":\"e2\""));
    assertTrue(response.contains("\"dps\":[[1431561600000,24.0,36.0]"));
    assertTrue(response.contains("[1431561660000,28.0,40.0]"));
    assertTrue(response.contains("[1431561720000,32.0,44.0]"));
    assertTrue(response.contains("\"id\":\"e3\""));
    assertTrue(response.contains("\"id\":\"e4\""));
    assertTrue(response.contains("\"dps\":[[1431561600000,48.0,72.0]"));
    assertTrue(response.contains("[1431561660000,56.0,80.0]"));
    assertTrue(response.contains("[1431561720000,64.0,88.0]"));
}
Also used : Query(net.opentsdb.query.pojo.Query) TSQuery(net.opentsdb.core.TSQuery) BaseTimeSyncedIteratorTest(net.opentsdb.query.expression.BaseTimeSyncedIteratorTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

TSQuery (net.opentsdb.core.TSQuery)10 Query (net.opentsdb.query.pojo.Query)10 BaseTimeSyncedIteratorTest (net.opentsdb.query.expression.BaseTimeSyncedIteratorTest)9 Test (org.junit.Test)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 Metric (net.opentsdb.query.pojo.Metric)2 Callback (com.stumbleupon.async.Callback)1 Deferred (com.stumbleupon.async.Deferred)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1 DataPoint (net.opentsdb.core.DataPoint)1 DataPoints (net.opentsdb.core.DataPoints)1 TSSubQuery (net.opentsdb.core.TSSubQuery)1 ExpressionDataPoint (net.opentsdb.query.expression.ExpressionDataPoint)1 ExpressionIterator (net.opentsdb.query.expression.ExpressionIterator)1 NumericFillPolicy (net.opentsdb.query.expression.NumericFillPolicy)1 TimeSyncedIterator (net.opentsdb.query.expression.TimeSyncedIterator)1 QueryStats (net.opentsdb.stats.QueryStats)1 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)1