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

Method validateAndSetQuery

src/core/TSQuery.java:168–210  ·  view source on GitHub ↗

Runs through query parameters to make sure it's a valid request. This includes parsing relative timestamps, verifying that the end time is later than the start time (or isn't set), that one or more metrics or TSUIDs are present, etc. If no exceptions are thrown, the query is considered valid. War

()

Source from the content-addressed store, hash-verified

166 * @throws IllegalArgumentException if something is wrong with the query
167 */
168 public void validateAndSetQuery() {
169 if (start == null || start.isEmpty()) {
170 throw new IllegalArgumentException("Missing start time");
171 }
172 start_time = DateTime.parseDateTimeString(start, timezone);
173
174 if (end != null && !end.isEmpty()) {
175 end_time = DateTime.parseDateTimeString(end, timezone);
176 } else {
177 end_time = System.currentTimeMillis();
178 }
179 if (end_time <= start_time) {
180 throw new IllegalArgumentException(
181 "End time [" + end_time + "] must be greater than the start time ["
182 + start_time +"]");
183 }
184
185 if (queries == null || queries.isEmpty()) {
186 throw new IllegalArgumentException("Missing queries");
187 }
188
189 // validate queries
190 int i = 0;
191 for (TSSubQuery sub : queries) {
192 sub.validateAndSetQuery();
193 final DownsamplingSpecification ds = sub.downsamplingSpecification();
194 if (ds != null && timezone != null && !timezone.isEmpty() &&
195 ds != DownsamplingSpecification.NO_DOWNSAMPLER) {
196 final TimeZone tz = DateTime.timezones.get(timezone);
197 if (tz == null) {
198 throw new IllegalArgumentException(
199 "The timezone specification could not be found");
200 }
201 ds.setTimezone(tz);
202 }
203 if (ds != null && use_calendar &&
204 ds != DownsamplingSpecification.NO_DOWNSAMPLER) {
205 ds.setUseCalendar(true);
206 }
207
208 sub.setIndex(i++);
209 }
210 }
211
212 /**
213 * Compiles the TSQuery into an array of Query objects for execution.

Calls 8

parseDateTimeStringMethod · 0.95
setTimezoneMethod · 0.95
setUseCalendarMethod · 0.95
isEmptyMethod · 0.80
setIndexMethod · 0.65
currentTimeMillisMethod · 0.45
getMethod · 0.45