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
}
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);
}
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;
}
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());
}
Aggregations