use of net.opentsdb.query.filter.TagVLiteralOrFilter.TagVILiteralOrFilter in project opentsdb by OpenTSDB.
the class TestTags method parseWithMetricAndFilters.
@Test
public void parseWithMetricAndFilters() {
final List<TagVFilter> filters = new ArrayList<TagVFilter>();
String metric = Tags.parseWithMetricAndFilters("sys.cpu.user", filters);
assertEquals("sys.cpu.user", metric);
assertEquals(0, filters.size());
filters.clear();
metric = Tags.parseWithMetricAndFilters("sys.cpu.user{host=web01}", filters);
assertEquals("sys.cpu.user", metric);
assertEquals(1, filters.size());
assertEquals("host", filters.get(0).getTagk());
assertTrue(filters.get(0).isGroupBy());
assertTrue(filters.get(0) instanceof TagVLiteralOrFilter);
filters.clear();
metric = Tags.parseWithMetricAndFilters("sys.cpu.user{host=*}", filters);
assertEquals("sys.cpu.user", metric);
assertEquals(1, filters.size());
assertEquals("host", filters.get(0).getTagk());
assertTrue(filters.get(0).isGroupBy());
assertTrue(filters.get(0) instanceof TagVWildcardFilter);
filters.clear();
metric = Tags.parseWithMetricAndFilters("sys.cpu.user{host=web01}{}", filters);
assertEquals("sys.cpu.user", metric);
assertEquals(1, filters.size());
assertEquals("host", filters.get(0).getTagk());
assertTrue(filters.get(0).isGroupBy());
assertTrue(filters.get(0) instanceof TagVLiteralOrFilter);
filters.clear();
metric = Tags.parseWithMetricAndFilters("sys.cpu.user{host=*,owner=regexp(.*ob)}", filters);
assertEquals("sys.cpu.user", metric);
assertEquals(2, filters.size());
for (final TagVFilter filter : filters) {
if (filter instanceof TagVWildcardFilter) {
assertEquals("host", filter.getTagk());
} else if (filter instanceof TagVRegexFilter) {
assertEquals("owner", filter.getTagk());
}
assertTrue(filter.isGroupBy());
}
filters.clear();
metric = Tags.parseWithMetricAndFilters("sys.cpu.user{}{host=web01}", filters);
assertEquals("sys.cpu.user", metric);
assertEquals(1, filters.size());
assertEquals("host", filters.get(0).getTagk());
assertFalse(filters.get(0).isGroupBy());
assertTrue(filters.get(0) instanceof TagVLiteralOrFilter);
filters.clear();
metric = Tags.parseWithMetricAndFilters("sys.cpu.user{}{host=iliteral_or(web01|Web02)}", filters);
assertEquals("sys.cpu.user", metric);
assertEquals(1, filters.size());
assertEquals("host", filters.get(0).getTagk());
assertFalse(filters.get(0).isGroupBy());
assertTrue(filters.get(0) instanceof TagVILiteralOrFilter);
filters.clear();
metric = Tags.parseWithMetricAndFilters("sys.cpu.user{}{host=iliteral_or(web01|Web02),owner=*}", filters);
assertEquals("sys.cpu.user", metric);
assertEquals(2, filters.size());
for (final TagVFilter filter : filters) {
if (filter instanceof TagVWildcardFilter) {
assertEquals("owner", filter.getTagk());
} else if (filter instanceof TagVILiteralOrFilter) {
assertEquals("host", filter.getTagk());
}
assertFalse(filter.isGroupBy());
}
filters.clear();
metric = Tags.parseWithMetricAndFilters("sys.cpu.user{host=iliteral_or(web01|Web02)}{owner=*}", filters);
assertEquals("sys.cpu.user", metric);
System.out.println(filters);
assertEquals(2, filters.size());
for (final TagVFilter filter : filters) {
if (filter instanceof TagVWildcardFilter) {
assertEquals("owner", filter.getTagk());
assertFalse(filter.isGroupBy());
} else if (filter instanceof TagVILiteralOrFilter) {
assertEquals("host", filter.getTagk());
assertTrue(filter.isGroupBy());
}
}
}
Aggregations