Search in sources :

Example 11 with ByteSet

use of net.opentsdb.utils.ByteSet in project opentsdb by OpenTSDB.

the class TestHistogramDataPointsToDataPointsAdaptor method doubleIteratorAllItems.

@Test
public void doubleIteratorAllItems() {
    List<HistogramDataPoint> row = new ArrayList<HistogramDataPoint>();
    for (int i = 0; i < 10; ++i) {
        row.add(new SimpleHistogramDataPointAdapter(new LongHistogramDataPointForTest(0, i), BASE_TIME + 5000L * i));
    }
    final HistogramSpan hspan = new HistogramSpan(tsdb);
    hspan.addRow(KEY, row);
    List<HistogramSpan> spans = new ArrayList<HistogramSpan>();
    spans.add(hspan);
    final ByteSet query_tags = new ByteSet();
    query_tags.add(new byte[] { 0, 0, 0, 1 });
    HistogramSpanGroup hist_span_group = new HistogramSpanGroup(tsdb, BASE_TIME, BASE_TIME + 5000L * 10, spans, HistogramAggregation.SUM, DownsamplingSpecification.NO_DOWNSAMPLER, 0, 0, 0, false, query_tags);
    HistogramDataPointsToDataPointsAdaptor dps_ada = new HistogramDataPointsToDataPointsAdaptor(hist_span_group, 0.98f);
    List<Double> values = new ArrayList<Double>();
    for (DataPoint dp : dps_ada) {
        assertFalse(dp.isInteger());
        values.add(dp.doubleValue());
    }
    // end for
    List<Double> values2 = new ArrayList<Double>();
    for (DataPoint dp : dps_ada) {
        values2.add(dp.doubleValue());
    }
    // end for
    assertTrue(dps_ada.isPercentile());
    List<Double> to_checks = new ArrayList<Double>();
    for (int i = 0; i < 10; ++i) {
        to_checks.add(i * 0.98);
    }
    // end for
    assertEquals(values.size(), to_checks.size());
    for (int i = 0; i < values.size(); ++i) {
        assertEquals(values.get(i).doubleValue(), to_checks.get(i).doubleValue(), 0.0001);
        assertEquals(values.get(i).doubleValue(), values2.get(i).doubleValue(), 0.0001);
    }
// end for
}
Also used : ArrayList(java.util.ArrayList) ByteSet(net.opentsdb.utils.ByteSet) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with ByteSet

use of net.opentsdb.utils.ByteSet in project opentsdb by OpenTSDB.

the class TestUnionIterator method beforeLocal.

@Before
public void beforeLocal() throws Exception {
    tags = new ByteMap<byte[]>();
    tags.put(UID1, UID1);
    tags.put(UID2, UID2);
    agg_tags = new ByteSet();
    agg_tags.add(UID3);
    fill_policy = new NumericFillPolicy(FillPolicy.NOT_A_NUMBER);
    sub = mock(ITimeSyncedIterator.class);
    query_tags = new ByteSet();
    query_tags.add(UID1);
    when(sub.getQueryTagKs()).thenReturn(query_tags);
    when(sub.getFillPolicy()).thenReturn(fill_policy);
}
Also used : ByteSet(net.opentsdb.utils.ByteSet) Before(org.junit.Before)

Example 13 with ByteSet

use of net.opentsdb.utils.ByteSet in project opentsdb by OpenTSDB.

the class UnionIterator method flattenTags.

/**
 * Creates a key based on the concatenation of the tag pairs then the agg
 * tag keys.
 * @param use_query_tags Whether or not to include tags returned with the
 * results or just use those group by'd in the query
 * @param include_agg_tags Whether or not to include the aggregated tags in
 * the identifier
 * @param dp The current expression data point
 * @param sub The sub query iterator
 * @return A byte array with the flattened tag keys and values. Note that
 * if the tags set is empty, this may return an empty array (but not a null
 * array)
 */
static byte[] flattenTags(final boolean use_query_tags, final boolean include_agg_tags, final ExpressionDataPoint dp, final ITimeSyncedIterator sub) {
    if (dp.tags() == null || dp.tags().isEmpty()) {
        return HBaseClient.EMPTY_ARRAY;
    }
    final int tagk_width = TSDB.tagk_width();
    final int tagv_width = TSDB.tagv_width();
    final ByteSet query_tagks;
    // NOTE: We MAY need the agg tags but I'm not sure yet
    final int tag_size;
    if (use_query_tags) {
        int i = 0;
        if (sub.getQueryTagKs() != null && !sub.getQueryTagKs().isEmpty()) {
            query_tagks = sub.getQueryTagKs();
            for (final Map.Entry<byte[], byte[]> pair : dp.tags().entrySet()) {
                if (query_tagks.contains(pair.getKey())) {
                    i++;
                }
            }
        } else {
            query_tagks = new ByteSet();
        }
        tag_size = i;
    } else {
        query_tagks = new ByteSet();
        tag_size = dp.tags().size();
    }
    final int length = (tag_size * (tagk_width + tagv_width)) + (include_agg_tags ? (dp.aggregatedTags().size() * tagk_width) : 0);
    final byte[] key = new byte[length];
    int idx = 0;
    for (final Entry<byte[], byte[]> pair : dp.tags().entrySet()) {
        if (use_query_tags && !query_tagks.contains(pair.getKey())) {
            continue;
        }
        System.arraycopy(pair.getKey(), 0, key, idx, tagk_width);
        idx += tagk_width;
        System.arraycopy(pair.getValue(), 0, key, idx, tagv_width);
        idx += tagv_width;
    }
    if (include_agg_tags) {
        for (final byte[] tagk : dp.aggregatedTags()) {
            System.arraycopy(tagk, 0, key, idx, tagk_width);
            idx += tagk_width;
        }
    }
    return key;
}
Also used : ByteSet(net.opentsdb.utils.ByteSet) HashMap(java.util.HashMap) Map(java.util.Map) ByteMap(org.hbase.async.Bytes.ByteMap)

Example 14 with ByteSet

use of net.opentsdb.utils.ByteSet in project opentsdb by OpenTSDB.

the class EDPtoDPS method getAggregatedTagsAsync.

@Override
public Deferred<List<String>> getAggregatedTagsAsync() {
    final ByteSet tagks = edps[index].aggregatedTags();
    final List<String> aggregated_tags = new ArrayList<String>(tagks.size());
    final List<Deferred<String>> names = new ArrayList<Deferred<String>>(tagks.size());
    for (final byte[] tagk : tagks) {
        names.add(tsdb.getUidName(UniqueIdType.TAGK, tagk));
    }
    /**
     * Adds the names to the aggregated_tags list
     */
    final class ResolveCB implements Callback<List<String>, ArrayList<String>> {

        @Override
        public List<String> call(final ArrayList<String> names) throws Exception {
            for (final String name : names) {
                aggregated_tags.add(name);
            }
            return aggregated_tags;
        }
    }
    return Deferred.group(names).addCallback(new ResolveCB());
}
Also used : Callback(com.stumbleupon.async.Callback) Deferred(com.stumbleupon.async.Deferred) ArrayList(java.util.ArrayList) ByteSet(net.opentsdb.utils.ByteSet)

Aggregations

ByteSet (net.opentsdb.utils.ByteSet)14 ByteMap (org.hbase.async.Bytes.ByteMap)8 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 GetRequest (org.hbase.async.GetRequest)2 Before (org.junit.Before)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Callback (com.stumbleupon.async.Callback)1 Deferred (com.stumbleupon.async.Deferred)1 LinkedList (java.util.LinkedList)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Matchers.anyList (org.mockito.Matchers.anyList)1