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"));
}
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:"));
}
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"));
}
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"));
}
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]"));
}
Aggregations