当前位置: 首页>>代码示例>>Java>>正文


Java QueryResult.getResults方法代码示例

本文整理汇总了Java中org.influxdb.dto.QueryResult.getResults方法的典型用法代码示例。如果您正苦于以下问题:Java QueryResult.getResults方法的具体用法?Java QueryResult.getResults怎么用?Java QueryResult.getResults使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.influxdb.dto.QueryResult的用法示例。


在下文中一共展示了QueryResult.getResults方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTimestamp

import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
/**
 * Returns the timestamp at the given series position.
 *
 * @param seriesPosition desired position
 * @return timestamp at given series position
 */
@NotNull
public Instant getTimestamp(int seriesPosition) {
    Instant cacheTimestamp = timestampCache.getIfPresent(seriesPosition);
    if (cacheTimestamp != null) {
        return cacheTimestamp;
    } else {
        logger.debug("Getting timestamp at position: " + seriesPosition);
    }

    Instant timestamp = null;
    if (seriesList != null) {
        timestamp = seriesList.get(seriesPosition);
    } else {
        QueryResult queryResult = influxDB.query(new Query(String.format(
                "SELECT %s FROM \"%s\" LIMIT 1 OFFSET %d",
                column, table, seriesPosition), database));

        for (QueryResult.Result result : queryResult.getResults()) {
            String timeString = (String) result.getSeries().get(0).getValues().get(0).get(0);
            timestamp = Instant.parse(timeString);
        }
    }

    if (timestamp != null) {
        timestampCache.put(seriesPosition, timestamp);
        return timestamp;
    } else {
        throw new IllegalStateException("Unable to determine timestamp at series position: " + seriesPosition);
    }
}
 
开发者ID:BFergerson,项目名称:Chronetic,代码行数:37,代码来源:ChronoSeries.java

示例2: read

import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
/**
 * Read the result of a request to read data loaded into influxdb
 *
 * @param request the specific request
 * @throws NullPointerException if request is null
 * @see MetricsLogger#metricsConnector
 */
public void read(String request) {
    Objects.requireNonNull(request);
    if (checkValidInfluxDBConnexion()) {
        final Query query = new Query(request, metricsConnector.getProperties().getDbName());
        QueryResult fixes = this.metricsConnector.getInfluxDB().query(query);
        List<QueryResult.Result> resultsList = fixes.getResults();
        resultsList.stream().filter(results -> results.getSeries() != null).forEach(results -> results.getSeries().forEach(series -> LOGGER.info(series.toString())));
    }
}
 
开发者ID:IKB4Stream,项目名称:IKB4Stream,代码行数:17,代码来源:MetricsLogger.java

示例3: listRetentionPolicies

import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
public Series listRetentionPolicies() throws InflowException {
  QueryResult queryResult = this.query(String.format("SHOW RETENTION POLICIES ON %s", this.name));
  List<Result> results = queryResult.getResults();
  Result result = results.get(0);
  List<Series> series = result.getSeries();
  Series serie = series.get(0);
  return serie;
  // callers can use series.getValuesAsStringArray();
}
 
开发者ID:nkiraly,项目名称:influxdb-inflow,代码行数:10,代码来源:Database.java

示例4: 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;
}
 
开发者ID:icclab,项目名称:cyclops-udr,代码行数:61,代码来源:CloudStackMeterV2.java

示例5: 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);
  }
 
开发者ID:mukatee,项目名称:kafka-consumer,代码行数:30,代码来源:InFluxJSONTests.java

示例6: 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);
  }
 
开发者ID:mukatee,项目名称:kafka-consumer,代码行数:30,代码来源:InFluxAvroTests.java

示例7: countEventsBetween

import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
/**
 * Counts the number of time events that occur during the given ChronoRange.
 *
 * @param chronoRange desired ChronoRange
 * @return amount of time events that occur during the given ChronoRange
 */
public int countEventsBetween(@NotNull ChronoRange chronoRange) {
    Integer cacheCount = cachePatternCount.getIfPresent(requireNonNull(chronoRange));
    if (cacheCount != null) {
        return cacheCount;
    } else if (chronoRange.getTimestampRanges().isEmpty()) {
        return 0;
    } else {
        logger.debug("Counting events between: " + chronoRange);
    }

    int count = 0;
    if (seriesList != null) {
        for (Instant timestamp : seriesList) {
            if (chronoRange.containsTime(timestamp)) {
                count++;
            }
        }
    } else {
        List<Instant[]> timestampRanges = chronoRange.getTimestampRanges();
        StringBuilder whereClause = new StringBuilder();
        boolean first = true;
        for (Instant[] timestampRange : timestampRanges) {
            if (first) {
                whereClause = whereClause.append("(");
                first = false;
            } else {
                whereClause = whereClause.append("OR (");
            }

            long startTime = timestampRange[0].getEpochSecond();
            startTime *= 1000000000L; //convert to nanoseconds
            startTime += timestampRange[0].getNano();

            long endTime = timestampRange[1].getEpochSecond();
            endTime *= 1000000000L; //convert to nanoseconds
            endTime += timestampRange[1].getNano();

            whereClause = whereClause.append("time >= ").append(startTime);
            whereClause = whereClause.append(" AND ");
            whereClause = whereClause.append("time <= ").append(endTime);
            whereClause = whereClause.append(") ");
        }

        QueryResult queryResult = influxDB.query(new Query(String.format(
                "SELECT COUNT(%s) FROM \"%s\" WHERE %s",
                column, table, whereClause.toString()), database));

        for (QueryResult.Result result : queryResult.getResults()) {
            if (result.getSeries() != null) {
                Double dbCount = (Double) result.getSeries().get(0).getValues().get(0).get(1);
                count += dbCount.intValue();
            }
        }
    }

    cachePatternCount.put(chronoRange, count);
    return count;
}
 
开发者ID:BFergerson,项目名称:Chronetic,代码行数:65,代码来源:ChronoSeries.java

示例8: getLastPull

import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
/**
 * Will look into database and return the date of last pull, or epoch if there was none
 * @return DateTime object
 */
public DateTime getLastPull() {
    InfluxDB db = getConnection();

    // this is epoch
    DateTime date = new DateTime(0, DateTimeZone.UTC);

    // prepare select query
    String select = "SELECT * FROM \"" + cloudStackEvents+ "\" WHERE event = 'pull' ORDER BY time DESC LIMIT 1";

    try {

        // fire up the query
        QueryResult response = db.query(createQuery(select, logsDb));

        // parse all results
        JSONArray resultArray = new JSONArray(response.getResults());

        // get first result
        JSONObject result = (JSONObject) resultArray.get(0);

        // get series
        JSONArray series = (JSONArray) result.get("series");

        // get first series
        JSONObject firstSeries = (JSONObject) series.get(0);

        // get values
        JSONArray values = (JSONArray) firstSeries.get("values");

        // use first value
        JSONArray firstValue = (JSONArray) values.get(0);

        // and finally our time
        String time = firstValue.get(0).toString();
        date = Time.getDateForTime(time);

    } catch (Exception e) {
        logger.debug("This is the first pull, therefore we will pull data since Epoch");
    }

    return date;
}
 
开发者ID:icclab,项目名称:cyclops-udr,代码行数:47,代码来源:InfluxDBClient.java

示例9: DTOList

import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
/**
 * This constructor will parse influxDB QueryResult and represent it as an object
 *
 * @param data
 */
public DTOList(QueryResult data) {
    columns = new ArrayList<String>();
    points = new ArrayList<List<String>>();

    Boolean onlyOnce = true;

    try {
        // go over all results
        for (QueryResult.Result result : data.getResults()) {
            // every series
            for (QueryResult.Series serie : result.getSeries()) {
                name = serie.getName();

                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));//TODO: Martin Manu, changed to String.valueOf from (String).
                        }
                    }

                    // and lastly, add them
                    points.add(line);
                }
            }
        }
    } catch (Exception ignored) {
        // in case of empty QueryResult body do nothing
    }
}
 
开发者ID:icclab,项目名称:cyclops-udr,代码行数:59,代码来源:DTOList.java

示例10: getLastPull

import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
/**
 * Will look into database and return the date of last pull, or epoch if there was none
 *
 * @return String
 */
public String getLastPull() {
    InfluxDB db = getConnection();

    // this is epoch
    String date = "";


    String select = "";

    // prepare select query
    if (Loader.getEnvironment().equals("Tnova")) {
        select = "select * from tnova_cdr order by desc limit 1";
        //TODO: create Configuration file property to get the table name
    } else if (Loader.getEnvironment().equals("Mcn")) {
        select = "select * from mcn_cdr order by desc limit 1";

    }

    try {

        // fire up the query
        QueryResult response = db.query(createQuery(select, dbName));

        // parse all results
        JSONArray resultArray = new JSONArray(response.getResults());

        // get first result
        JSONObject result = (JSONObject) resultArray.get(0);

        // get series
        JSONArray series = (JSONArray) result.get("series");

        // get first series
        JSONObject firstSeries = (JSONObject) series.get(0);

        // get values
        JSONArray values = (JSONArray) firstSeries.get("values");

        // use first value
        JSONArray firstValue = (JSONArray) values.get(0);

        // and finally our time
        date = firstValue.get(0).toString().replace("Z", "");

    } catch (Exception e) {
        logger.debug("This is the first pull, therefore we will pull data since Epoch");
    }

    return date;
}
 
开发者ID:icclab,项目名称:cyclops-rc,代码行数:56,代码来源:InfluxDBClient.java


注:本文中的org.influxdb.dto.QueryResult.getResults方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。