MCPcopy
hub / github.com/OpenTSDB/opentsdb / AggregationIterator

Class AggregationIterator

src/core/AggregationIterator.java:120–846  ·  view source on GitHub ↗

Iterator that aggregates multiple spans or time series data and does linear interpolation (lerp) for missing data points. This where the real business of SpanGroup is. This iterator provides a merged, aggregated view of multiple Spans. The data points in all the Spans are retur

Source from the content-addressed store, hash-verified

118 * <p>
119 */
120public class AggregationIterator implements SeekableView, DataPoint,
121 Aggregator.Longs, Aggregator.Doubles {
122
123 private static final Logger LOG =
124 LoggerFactory.getLogger(AggregationIterator.class);
125
126 /** Extra bit we set on the timestamp of floating point values. */
127 private static final long FLAG_FLOAT = 0x8000000000000000L;
128
129 /** Mask to use in order to get rid of the flag above.
130 * This value also conveniently represents the largest timestamp we can
131 * possibly store, provided that the most significant bit is reserved by
132 * FLAG_FLOAT.
133 */
134 protected static final long TIME_MASK = 0x7FFFFFFFFFFFFFFFL;
135
136 /** Aggregator to use to aggregate data points from different Spans. */
137 private final Aggregator aggregator;
138
139 /** Interpolation method to use when aggregating time series */
140 private final Interpolation method;
141
142 /** If true, use rate of change instead of actual values. */
143 private final boolean rate;
144
145 /**
146 * Where we are in each {@link Span} in the group.
147 * The iterators in this array always points to 2 values ahead of the
148 * current value, as we pre-load the current and the next values into the
149 * {@link #timestamps} and {@link #values} member.
150 * Once we reach the end of a Span, we'll null out its iterator from this
151 * array.
152 */
153 protected final SeekableView[] iterators;
154
155 /** Start time (UNIX timestamp in seconds or ms) on 32 bits ("unsigned" int). */
156 protected final long start_time;
157
158 /** End time (UNIX timestamp in seconds or ms) on 32 bits ("unsigned" int). */
159 protected final long end_time;
160
161 /**
162 * The current and previous timestamps for the data points being used.
163 * <p>
164 * Are we computing a rate?
165 * <ul>
166 * <li>No: for {@code iterators[i]} the timestamp of the current data
167 * point is {@code timestamps[i]} and the timestamp of the next data
168 * point is {@code timestamps[iterators.length + i]}.</li>
169 * </ul>
170 * <p>
171 * Each timestamp can have the {@code FLAG_FLOAT} applied so it's important
172 * to use the {@code TIME_MASK} when getting the actual timestamp value
173 * out of it.
174 * There are two special values for timestamps:
175 * <ul>
176 * <li>{@code 0} when in the first half of the array: this iterator has
177 * run out of data points and must not be used anymore.</li>

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…