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

Class IntersectionIterator

src/query/expression/IntersectionIterator.java:57–521  ·  view source on GitHub ↗

This class handles taking a set of queries and their results and iterates over each series in each set with time alignment after computing the intersection of all sets. The iterator performs the following: - calculates the intersection of all queries based on the tags or query tags and optiona

Source from the content-addressed store, hash-verified

55 * @since 2.3
56 */
57public class IntersectionIterator implements ITimeSyncedIterator, VariableIterator {
58 private static final Logger LOG = LoggerFactory.getLogger(IntersectionIterator.class);
59
60 /** The queries compiled and fetched from storage */
61 private final Map<String, ITimeSyncedIterator> queries;
62
63 /** A list of the current values for each series post intersection */
64 private final Map<String, ExpressionDataPoint[]> current_values;
65
66 /** A map of the sub query index to their names for intersection computation */
67 private final String[] index_to_names;
68
69 /** Whether or not to intersect on the query tagks instead of the result set
70 * tagks */
71 private final boolean intersect_on_query_tagks;
72
73 /** Whether or not to include the aggregated tags in the result set */
74 private final boolean include_agg_tags;
75
76 /** The start/current timestamp for the iterator in ms */
77 private long timestamp;
78
79 /** Post intersection number of time series */
80 private int series_size;
81
82 /** The ID of this iterator */
83 private final String id;
84
85 /** The index of this iterator in a list of iterators */
86 private int index;
87
88 /**
89 * Ctor to create the expression lock-step iterator from a set of query results.
90 * If the results map is empty, then the ctor will complete but the results map
91 * will be empty and calls to {@link #hasNext()} will always return false.
92 * @param results The query results to store
93 * @param intersect_on_query_tagks Whether or not to include only the query
94 * specified tags during intersection
95 * @param include_agg_tags Whether or not to include aggregated tags during
96 * intersection
97 * @throws IllegalDataException if, after computing the intersection, no results
98 * would be left.
99 */
100 public IntersectionIterator(final String id, final Map<String, ITimeSyncedIterator> results,
101 final boolean intersect_on_query_tagks, final boolean include_agg_tags) {
102 this.id = id;
103 this.intersect_on_query_tagks = intersect_on_query_tagks;
104 this.include_agg_tags = include_agg_tags;
105 timestamp = Long.MAX_VALUE;
106 queries = new HashMap<String, ITimeSyncedIterator>(results.size());
107 current_values = new HashMap<String, ExpressionDataPoint[]>(results.size());
108 index_to_names = new String[results.size()];
109
110 int max_series = 0;
111 int i = 0;
112 for (final Map.Entry<String, ITimeSyncedIterator> entry : results.entrySet()) {
113 if (LOG.isDebugEnabled()) {
114 LOG.debug("Adding iterator " + entry.getValue());

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…