本文整理汇总了Java中org.influxdb.dto.QueryResult.Series方法的典型用法代码示例。如果您正苦于以下问题:Java QueryResult.Series方法的具体用法?Java QueryResult.Series怎么用?Java QueryResult.Series使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.influxdb.dto.QueryResult
的用法示例。
在下文中一共展示了QueryResult.Series方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addSeries
import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
public void addSeries(QueryResult.Series series) {
final GroupName group = seriesToGroupName(series);
final Optional<Histogram.Range> range = rangeFromSeries(series);
final int timeColumnIdx = InfluxUtil.getColumnIndexFromSeries(series, TIME_COLUMN).orElseThrow(() -> new IllegalStateException("missing time column"));
series.getValues().forEach(row -> {
assert series.getColumns().size() == row.size();
final DateTime timestamp = new DateTime(((Number) row.get(timeColumnIdx)).longValue());
final IntermediateTSV valueMap = new IntermediateTSV();
final ListIterator<String> columnIter = series.getColumns().listIterator();
final Iterator<Object> rowIter = row.iterator();
while (rowIter.hasNext()) {
final Object field = rowIter.next();
final int columnIdx = columnIter.nextIndex();
final String columnName = columnIter.next();
if (columnIdx != timeColumnIdx && field != null)
valueMap.addMetric(valueKeyToMetricName(columnName), range, seriesValueToMetricValue(field));
}
datums.merge(new TimestampedGroup(timestamp, group), valueMap, IntermediateTSV::withMerged);
});
}
示例2: testListUsers
import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
@Test
public void testListUsers() throws Exception {
// create users.example.json as Series object
QueryResult.Series expectedSeries = new QueryResult.Series();
List<String> expectedColumns = new ArrayList<>();
expectedColumns.add("user");
expectedColumns.add("admin");
expectedSeries.setColumns(expectedColumns);
this.doTestResponse(
"/users.example.json",
"listUsers",
expectedSeries
);
}
示例3: getColumnFromSeries
import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
protected static Optional<Stream<Object>> getColumnFromSeries(QueryResult.Series series, String columnName) {
return getColumnIndexFromSeries(series, columnName)
.map(idx -> {
return series.getValues().stream()
.map(row -> row.get(idx));
});
}
示例4: seriesToGroupName
import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
private static GroupName seriesToGroupName(QueryResult.Series series) {
final SimpleGroupPath groupPath = pathStrToGroupPath(series.getName());
final Tags tags;
if (series.getTags() == null) {
tags = Tags.EMPTY;
} else {
tags = Tags.valueOf(series.getTags().entrySet().stream()
.filter(tagEntry -> !Objects.equals(tagEntry.getKey(), InfluxUtil.MONSOON_RANGE_TAG))
.filter(tagEntry -> tagEntry.getValue() != null)
.map(tagEntry -> SimpleMapEntry.create(tagEntry.getKey(), tagValueToMetricValue(tagEntry.getValue()))));
}
return GroupName.valueOf(groupPath, tags);
}
示例5: rangeFromSeries
import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
private static Optional<Histogram.Range> rangeFromSeries(QueryResult.Series series) {
if (series.getTags() == null) return Optional.empty();
return series.getTags().entrySet().stream()
.filter(tagEntry -> Objects.equals(tagEntry.getKey(), InfluxUtil.MONSOON_RANGE_TAG))
.map(Map.Entry::getValue)
.filter(Objects::nonNull)
.map(rangeStr -> rangeStr.split(Pattern.quote(".."), 2))
.map(parts -> new Histogram.Range(Double.parseDouble(parts[0]), Double.parseDouble(parts[1])))
.findAny();
}
示例6: listDatabases
import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
/**
* List all the databases
*/
public QueryResult.Series listDatabases() throws InflowException {
QueryResult queryResult = this.query(null, "SHOW DATABASES");
QueryResult.Result result = queryResult.getResults().get(0);
QueryResult.Series series = result.getSeries().get(0);
return series;
// callers can use series.getValuesAsStringArray();
}
示例7: listUsers
import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
/**
* List all the users
*
*/
public QueryResult.Series listUsers() throws InflowException {
QueryResult queryResult = this.query(null, "SHOW USERS");
QueryResult.Result result = queryResult.getResults().get(0);
QueryResult.Series series = result.getSeries().get(0);
return series;
// calle1s can use series.getValuesAsStringArray();
}
示例8: testListDatabases
import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
@Test
public void testListDatabases() throws Exception {
// create databases.example.json as Series object
QueryResult.Series expectedSeries = new QueryResult.Series();
expectedSeries.setName("databases");
List<String> expectedColumns = new ArrayList<>();
expectedColumns.add("name");
expectedSeries.setColumns(expectedColumns);
List<List<Object>> values = new ArrayList<>();
List<Object> testObject = new ArrayList<>();
testObject.add("test");
values.add(testObject);
List<Object> test1Object = new ArrayList<>();
test1Object.add("test1");
values.add(test1Object);
List<Object> test2Object = new ArrayList<>();
test2Object.add("test2");
values.add(test2Object);
expectedSeries.setValues(values);
this.doTestResponse("/databases.example.json", "listDatabases", expectedSeries);
}
示例9: doTestResponse
import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
protected void doTestResponse(String responseFile, String method, QueryResult.Series expectedSeries) throws Exception {
Client client = this.getClient(this.TEST_TARGET_USERNAME, this.TEST_TARGET_PASSWORD);
// setup a mock driver that always returns responseFile contents as QueryResult object
DriverOnlyStubs mockDriver = Mockito.mock(DriverOnlyStubs.class);
final String expectedResponseJson = this.loadResourceFileDataAsString(responseFile);
Mockito.when(mockDriver.query(any(Query.class))).thenAnswer(new Answer<QueryResult>() {
@Override
public QueryResult answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
Client.setLastQuery(((Query)args[0]).getCommand());
Gson gson = new Gson();
QueryResult qr = gson.fromJson(expectedResponseJson, QueryResult.class);
return qr;
}
});
// specify the client to use the mockDriver we just built to return the expected response
client.setDriver(mockDriver);
Class noParam[] = {};
//Class[] oneStringParam= new Class[1];
//oneStringParam[0] = String.class;
Method callMethod = Client.class.getDeclaredMethod(method, noParam);
QueryResult.Series resultSeries = (QueryResult.Series) callMethod.invoke(client, null);
assertEquals(
resultSeries,
expectedSeries
);
}
示例10: retrieveMeterList
import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
/**
* Ask for meterList from database
*
* @return MeterList object
*/
protected StandardMeter[] retrieveMeterList() {
String query = new MeterList().createDBQuery();
// run query
QueryResult result = dbClient.runQuery(query);
ArrayList<String> columns = new ArrayList<String>();
ArrayList<List<String>> points = new ArrayList<List<String>>();
Boolean onlyOnce = true;
int nameIndex, sourceIndex;
ArrayList<StandardMeter> meters = new ArrayList<StandardMeter>();
try {
// go over all results
for (QueryResult.Result data : result.getResults()) {
// every series
for (QueryResult.Series serie : data.getSeries()) {
Map<String, String> tags = serie.getTags();
// add all column names
if (onlyOnce) {
if (tags != null) {
columns.addAll(tags.keySet());
}
columns.addAll(serie.getColumns());
onlyOnce = false;
}
// iterate over values
for (List<Object> values : serie.getValues()) {
List<String> line = new ArrayList<String>();
// don't forget to manually add tags here
if (tags != null) {
line.addAll(tags.values());
}
// cast them to String
for (Object value : values) {
if (value == null) {
line.add("");
} else {
line.add(String.valueOf(value));
}
}
// and lastly, add them
points.add(line);
}
}
}
nameIndex = columns.indexOf("metername");
sourceIndex = columns.indexOf("metersource");
for(List<String> point : points){
meters.add(new StandardMeter(point.get(nameIndex), point.get(sourceIndex)));
}
} catch (Exception ignored) {
// in case of empty QueryResult body do nothing
}
StandardMeter[] ret = new StandardMeter[meters.size()];
ret = meters.toArray(ret);
return ret;
}
示例11: assertMeasure
import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
private void assertMeasure(QueryResult result, int serieIndex, int measureIndex, int valueCount, int serieCount, String oid, String address,
String tom, String type, String expectedName, Object expectedValue) {
List<QueryResult.Result> items = result.getResults();
assertEquals(items.size(), 1, "Number of results");
QueryResult.Result item1 = items.get(0);
List<QueryResult.Series> series = item1.getSeries();
assertNotNull(series, "Series should not be null in "+item1);
assertEquals(series.size(), serieCount, "Number of series");
QueryResult.Series series1 = series.get(serieIndex);
List<List<Object>> valuesList = series1.getValues();
assertEquals(valuesList.size(), valueCount, "Number of values");
// Map<String, String> tags = series1.getTags();
// assertEquals(tags.size(), 4, "Number of tags created");
// assertEquals(tags.get("oid"), oid);
// assertEquals(tags.get("address"), address);
// assertEquals(tags.get("tom"), tom);
//fourth tag is influxdb internal
List<String> columns = series1.getColumns();
assertEquals(columns.toString(), "[time, "+type+", oid, target, tom]", "Columns created");
List<Object> measures = valuesList.get(measureIndex);
assertEquals(measures.size(), 5, "Number of measures"); //this is "time", "value", oid, address, tom
Object value = measures.get(columns.indexOf(type));
assertEquals(value, expectedValue, "Value for measure "+measureIndex+" in series "+serieIndex);
assertEquals(measures.get(columns.indexOf("oid")), oid);
assertEquals(measures.get(columns.indexOf("target")), address);
assertEquals(measures.get(columns.indexOf("tom")), tom);
String name = series1.getName();
assertEquals(name, expectedName);
}
示例12: assertMeasure
import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
private void assertMeasure(QueryResult result, int serieIndex, int measureIndex, int valueCount, int serieCount, String oid, String address,
String tom, String type, String expectedName, Object expectedValue) {
List<QueryResult.Result> items = result.getResults();
assertEquals(items.size(), 1, "Number of results");
QueryResult.Result item1 = items.get(0);
List<QueryResult.Series> series = item1.getSeries();
assertNotNull(series, "Series should not be null in "+item1);
assertEquals(series.size(), serieCount, "Number of series");
QueryResult.Series series1 = series.get(serieIndex);
List<List<Object>> valuesList = series1.getValues();
assertEquals(valuesList.size(), valueCount, "Number of values");
// Map<String, String> tags = series1.getTags();
// assertEquals(tags.size(), 4, "Number of tags created");
// assertEquals(tags.get("oid"), oid);
// assertEquals(tags.get("address"), address);
// assertEquals(tags.get("tom"), tom);
//fourth tag is influxdb internal
List<String> columns = series1.getColumns();
assertEquals(columns.toString(), "[time, address, oid, tom, "+type+"]", "Columns created");
List<Object> measures = valuesList.get(measureIndex);
assertEquals(measures.size(), 5, "Number of measures"); //this is "time", "value", oid, address, tom
Object value = measures.get(columns.indexOf(type));
assertEquals(value, expectedValue, "Value for measure "+measureIndex+" in series "+serieIndex);
assertEquals(measures.get(columns.indexOf("oid")), oid);
assertEquals(measures.get(columns.indexOf("address")), address);
assertEquals(measures.get(columns.indexOf("tom")), tom);
String name = series1.getName();
assertEquals(name, expectedName);
}
示例13: loadLatestValue
import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
protected Long loadLatestValue(String metric) {
Query query = new Query("SELECT " + METRIC_VALUE_FIELD + " FROM \"" + metric + "\" ORDER BY time DESC LIMIT 1", database);
QueryResult result = influxDb.query(query);
assertNull(result.getError());
assertFalse(result.hasError());
QueryResult.Result row = result.getResults().get(0);
say("Loaded InfluxDB results: " + row);
Number number = null;
if (row.getSeries() != null && !row.getSeries().isEmpty()) {
QueryResult.Series series = row.getSeries().get(0);
int valueIdx = series.getColumns().indexOf(METRIC_VALUE_FIELD);
assertTrue("Real index=" + valueIdx, valueIdx >= 0);
number = (Number)series.getValues().get(0).get(valueIdx);
}
return number != null ? number.longValue() : null;
}
示例14: getColumnIndexFromSeries
import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
protected static Optional<Integer> getColumnIndexFromSeries(QueryResult.Series series, String columnName) {
return Optional.of(series.getColumns().indexOf(columnName))
.filter(idx -> idx >= 0);
}
示例15: testListDatabasesWithMockDriver
import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
@Test
public void testListDatabasesWithMockDriver() throws Exception {
// create databases.example.json as Series object
QueryResult.Series expectedSeries = new QueryResult.Series();
expectedSeries.setName("databases");
List<String> expectedColumns = new ArrayList<>();
expectedColumns.add("name");
expectedSeries.setColumns(expectedColumns);
List<List<Object>> values = new ArrayList<>();
List<Object> testObject = new ArrayList<>();
testObject.add("test");
values.add(testObject);
List<Object> test1Object = new ArrayList<>();
test1Object.add("test1");
values.add(test1Object);
List<Object> test2Object = new ArrayList<>();
test2Object.add("test2");
values.add(test2Object);
expectedSeries.setValues(values);
// create client with mock driver that will list dbs based on databases.example.json when asked
Client client = this.getClient(this.TEST_TARGET_USERNAME, this.TEST_TARGET_PASSWORD);
DriverInterface mockDriver = this.getMockClientThatListsTestDbs();
client.setDriver(mockDriver);
QueryResult.Series resultSeries = client.listDatabases();
// compare list database results to expected
assertEquals(
resultSeries,
expectedSeries
);
// make sure SHOW DATABASES is the query that was run
assertEquals(
Client.getLastQuery(),
"SHOW DATABASES"
);
}