Search in sources :

Example 6 with TagVFilter

use of net.opentsdb.query.filter.TagVFilter in project opentsdb by OpenTSDB.

the class TestTsdbQuery method configureFromQueryWithFilter.

@Test
public void configureFromQueryWithFilter() throws Exception {
    setDataPointStorage();
    final TSQuery ts_query = getTSQuery();
    final List<TagVFilter> filters = new ArrayList<TagVFilter>(1);
    filters.add(new TagVWildcardFilter("host", "*imes"));
    ts_query.getQueries().get(0).setFilters(filters);
    ts_query.validateAndSetQuery();
    query = new TsdbQuery(tsdb);
    query.configureFromQuery(ts_query, 0).joinUninterruptibly();
    assertArrayEquals(METRIC_BYTES, ForTesting.getMetric(query));
    assertEquals(1, ForTesting.getFilters(query).size());
    assertNull(ForTesting.getGroupBys(query));
    assertEquals(1, ForTesting.getRowKeyLiterals(query).size());
    assertNull(ForTesting.getRowKeyLiterals(query).get(TAGV_BYTES));
    assertNotNull(ForTesting.getRateOptions(query));
}
Also used : TagVFilter(net.opentsdb.query.filter.TagVFilter) TagVWildcardFilter(net.opentsdb.query.filter.TagVWildcardFilter) ArrayList(java.util.ArrayList) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with TagVFilter

use of net.opentsdb.query.filter.TagVFilter in project opentsdb by OpenTSDB.

the class TestQuery method setup.

@Before
public void setup() {
    time = Timespan.Builder().setStart("3h-ago").setAggregator("avg").setEnd("1h-ago").setTimezone("UTC").setDownsampler(Downsampler.Builder().setInterval("15m").setAggregator("avg").setFillPolicy(new NumericFillPolicy(FillPolicy.NOT_A_NUMBER)).build()).build();
    TagVFilter tag = new TagVFilter.Builder().setFilter("*").setGroupBy(false).setTagk("host").setType("iwildcard").build();
    filter = Filter.Builder().setId("f1").setTags(Arrays.asList(tag)).build();
    metric = Metric.Builder().setMetric("YAMAS.cpu.idle").setId("m1").setFilter("f1").setTimeOffset("0").setAggregator("sum").build();
    expression = Expression.Builder().setId("e1").setExpression("m1 * 1024").setJoin(Join.Builder().setOperator(SetOperator.UNION).build()).build();
    output = Output.Builder().setId("m1").setAlias("CPU Idle EAST DC").build();
}
Also used : TagVFilter(net.opentsdb.query.filter.TagVFilter) NumericFillPolicy(net.opentsdb.query.expression.NumericFillPolicy) Before(org.junit.Before)

Example 8 with TagVFilter

use of net.opentsdb.query.filter.TagVFilter in project opentsdb by OpenTSDB.

the class TSSubQuery method toString.

public String toString() {
    final StringBuilder buf = new StringBuilder();
    buf.append("TSSubQuery(metric=").append(metric == null || metric.isEmpty() ? "" : metric);
    buf.append(", filters=[");
    if (filters != null && !filters.isEmpty()) {
        int counter = 0;
        for (final TagVFilter filter : filters) {
            if (counter > 0) {
                buf.append(", ");
            }
            buf.append(filter);
            ++counter;
        }
    }
    buf.append("], tsuids=[");
    if (tsuids != null && !tsuids.isEmpty()) {
        int counter = 0;
        for (String tsuid : tsuids) {
            if (counter > 0) {
                buf.append(", ");
            }
            buf.append(tsuid);
            counter++;
        }
    }
    buf.append("], agg=").append(aggregator).append(", downsample=").append(downsample).append(", ds_interval=").append(downsample_specifier.getInterval()).append(", rate=").append(rate).append(", rate_options=").append(rate_options).append(", explicit_tags=").append("explicit_tags").append(", index=").append(index).append(")");
    return buf.toString();
}
Also used : TagVFilter(net.opentsdb.query.filter.TagVFilter)

Example 9 with TagVFilter

use of net.opentsdb.query.filter.TagVFilter in project opentsdb by OpenTSDB.

the class TsdbQuery method setTimeSeries.

@Override
public void setTimeSeries(final String metric, final Map<String, String> tags, final Aggregator function, final boolean rate, final RateOptions rate_options) throws NoSuchUniqueName {
    if (filters == null) {
        filters = new ArrayList<TagVFilter>(tags.size());
    }
    TagVFilter.tagsToFilters(tags, filters);
    try {
        for (final TagVFilter filter : this.filters) {
            filter.resolveTagkName(tsdb).join();
        }
    } catch (final InterruptedException e) {
        LOG.warn("Interrupted", e);
        Thread.currentThread().interrupt();
    } catch (final NoSuchUniqueName e) {
        throw e;
    } catch (final Exception e) {
        if (e instanceof DeferredGroupException) {
            // rollback to the actual case. The DGE missdirects
            Throwable ex = e.getCause();
            while (ex != null && ex instanceof DeferredGroupException) {
                ex = ex.getCause();
            }
            if (ex != null) {
                throw (RuntimeException) ex;
            }
        }
        LOG.error("Unexpected exception processing group bys", e);
        throw new RuntimeException(e);
    }
    findGroupBys();
    this.metric = tsdb.metrics.getId(metric);
    aggregator = function;
    this.rate = rate;
    this.rate_options = rate_options;
}
Also used : TagVFilter(net.opentsdb.query.filter.TagVFilter) DeferredGroupException(com.stumbleupon.async.DeferredGroupException) DeferredGroupException(com.stumbleupon.async.DeferredGroupException) HBaseException(org.hbase.async.HBaseException) NoSuchUniqueName(net.opentsdb.uid.NoSuchUniqueName)

Example 10 with TagVFilter

use of net.opentsdb.query.filter.TagVFilter in project opentsdb by OpenTSDB.

the class TsdbQuery method findGroupBys.

/**
   * Populates the {@link #group_bys} and {@link #row_key_literals}'s with 
   * values pulled from the filters. 
   */
private void findGroupBys() {
    if (filters == null || filters.isEmpty()) {
        return;
    }
    row_key_literals = new ByteMap<byte[][]>();
    Collections.sort(filters);
    final Iterator<TagVFilter> current_iterator = filters.iterator();
    final Iterator<TagVFilter> look_ahead = filters.iterator();
    byte[] tagk = null;
    TagVFilter next = look_ahead.hasNext() ? look_ahead.next() : null;
    int row_key_literals_count = 0;
    while (current_iterator.hasNext()) {
        next = look_ahead.hasNext() ? look_ahead.next() : null;
        int gbs = 0;
        // sorted!
        final ByteMap<Void> literals = new ByteMap<Void>();
        final List<TagVFilter> literal_filters = new ArrayList<TagVFilter>();
        TagVFilter current = null;
        do {
            // yeah, I'm breakin out the do!!!
            current = current_iterator.next();
            if (tagk == null) {
                tagk = new byte[TSDB.tagk_width()];
                System.arraycopy(current.getTagkBytes(), 0, tagk, 0, TSDB.tagk_width());
            }
            if (current.isGroupBy()) {
                gbs++;
            }
            if (!current.getTagVUids().isEmpty()) {
                for (final byte[] uid : current.getTagVUids()) {
                    literals.put(uid, null);
                }
                literal_filters.add(current);
            }
            if (next != null && Bytes.memcmp(tagk, next.getTagkBytes()) != 0) {
                break;
            }
            next = look_ahead.hasNext() ? look_ahead.next() : null;
        } while (current_iterator.hasNext() && Bytes.memcmp(tagk, current.getTagkBytes()) == 0);
        if (gbs > 0) {
            if (group_bys == null) {
                group_bys = new ArrayList<byte[]>();
            }
            group_bys.add(current.getTagkBytes());
        }
        if (literals.size() > 0) {
            if (literals.size() + row_key_literals_count > tsdb.getConfig().getInt("tsd.query.filter.expansion_limit")) {
                LOG.debug("Skipping literals for " + current.getTagk() + " as it exceedes the limit");
            } else {
                final byte[][] values = new byte[literals.size()][];
                literals.keySet().toArray(values);
                row_key_literals.put(current.getTagkBytes(), values);
                row_key_literals_count += values.length;
                for (final TagVFilter filter : literal_filters) {
                    filter.setPostScan(false);
                }
            }
        } else {
            row_key_literals.put(current.getTagkBytes(), null);
        }
    }
}
Also used : TagVFilter(net.opentsdb.query.filter.TagVFilter) ByteMap(org.hbase.async.Bytes.ByteMap) ArrayList(java.util.ArrayList)

Aggregations

TagVFilter (net.opentsdb.query.filter.TagVFilter)15 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)7 TagVWildcardFilter (net.opentsdb.query.filter.TagVWildcardFilter)5 Callback (com.stumbleupon.async.Callback)3 Deferred (com.stumbleupon.async.Deferred)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 DeferredGroupException (com.stumbleupon.async.DeferredGroupException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TSSubQuery (net.opentsdb.core.TSSubQuery)2 ByteMap (org.hbase.async.Bytes.ByteMap)2 HBaseException (org.hbase.async.HBaseException)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 DataPoint (net.opentsdb.core.DataPoint)1 DataPoints (net.opentsdb.core.DataPoints)1 IncomingDataPoint (net.opentsdb.core.IncomingDataPoint)1