MCPcopy Index your code
hub / github.com/OpenTSDB/opentsdb / doQuery

Method doQuery

src/tools/CliQuery.java:105–150  ·  view source on GitHub ↗
(final TSDB tsdb,
                              final String args[],
                              final boolean want_plot)

Source from the content-addressed store, hash-verified

103 }
104
105 private static Plot doQuery(final TSDB tsdb,
106 final String args[],
107 final boolean want_plot) {
108 final ArrayList<String> plotparams = new ArrayList<String>();
109 final ArrayList<Query> queries = new ArrayList<Query>();
110 final ArrayList<String> plotoptions = new ArrayList<String>();
111 parseCommandLineQuery(args, tsdb, queries, plotparams, plotoptions);
112 if (queries.isEmpty()) {
113 usage(null, "Not enough arguments, need at least one query.", 2);
114 }
115
116 final Plot plot = (want_plot ? new Plot(queries.get(0).getStartTime(),
117 queries.get(0).getEndTime())
118 : null);
119 if (want_plot) {
120 plot.setParams(parsePlotParams(plotparams));
121 }
122 final int nqueries = queries.size();
123 for (int i = 0; i < nqueries; i++) {
124 // TODO(tsuna): Optimization: run each query in parallel.
125 final StringBuilder buf = want_plot ? null : new StringBuilder();
126 for (final DataPoints datapoints : queries.get(i).run()) {
127 if (want_plot) {
128 plot.add(datapoints, plotoptions.get(i));
129 } else {
130 final String metric = datapoints.metricName();
131 final String tagz = datapoints.getTags().toString();
132 for (final DataPoint datapoint : datapoints) {
133 buf.append(metric)
134 .append(' ')
135 .append(datapoint.timestamp())
136 .append(' ');
137 if (datapoint.isInteger()) {
138 buf.append(datapoint.longValue());
139 } else {
140 buf.append(String.format("%f", datapoint.doubleValue()));
141 }
142 buf.append(' ').append(tagz).append('\n');
143 System.out.print(buf);
144 buf.delete(0, buf.length());
145 }
146 }
147 }
148 }
149 return plot;
150 }
151
152 /**
153 * Parses the query from the command lines.

Callers 1

mainMethod · 0.95

Calls 15

parseCommandLineQueryMethod · 0.95
usageMethod · 0.95
setParamsMethod · 0.95
parsePlotParamsMethod · 0.95
addMethod · 0.95
isEmptyMethod · 0.80
getStartTimeMethod · 0.65
getEndTimeMethod · 0.65
sizeMethod · 0.65
runMethod · 0.65
metricNameMethod · 0.65
getTagsMethod · 0.65

Tested by

no test coverage detected