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


Java QueryResult类代码示例

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


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

示例1: execInfluxdbQuery

import org.influxdb.dto.QueryResult; //导入依赖的package包/类
private Status execInfluxdbQuery(String sql) {
	long costTime = 0L;
	try {
		//TODO 需要完善
		long startTime1=System.nanoTime();
		QueryResult results = INFLUXDB.query(new Query(sql, DB_NAME));
		long endTime1=System.nanoTime();
		costTime=endTime1-startTime1;
		if(results.hasError()) {
			return Status.FAILED(costTime);
		}else {
			return Status.OK(costTime);
		}
	} catch (Exception e) {
		e.printStackTrace();
		return Status.FAILED(0L);
	}
}
 
开发者ID:dbiir,项目名称:ts-benchmark,代码行数:19,代码来源:InfluxDB2.java

示例2: metric

import org.influxdb.dto.QueryResult; //导入依赖的package包/类
@Override
public InfluxMetric metric(NodeId nodeId, String metricName) {
    String queryString = new StringBuilder()
            .append("SELECT m1_rate FROM ")
            .append(database)
            .append(METRIC_DELIMITER)
            .append(quote(DEFAULT_POLICY))
            .append(METRIC_DELIMITER)
            .append(quote(nodeId + METRIC_DELIMITER + metricName))
            .append(" LIMIT 1")
            .toString();

    Query query = new Query(queryString, database);
    List<QueryResult.Result> results = influxDB.query(query).getResults();

    if (results != null && results.get(0) != null
            && results.get(0).getSeries() != null) {
        return new DefaultInfluxMetric.Builder()
                .time((String) results.get(0).getSeries().get(0).getValues().get(0).get(0))
                .oneMinRate((Double) results.get(0).getSeries().get(0)
                        .getValues().get(0).get(1)).build();
    }

    return null;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:26,代码来源:DefaultInfluxDbMetricsRetriever.java

示例3: allMetricNames

import org.influxdb.dto.QueryResult; //导入依赖的package包/类
/**
 * Returns all metric names that bound with node identification.
 *
 * @return all metric names
 */
protected Map<NodeId, Set<String>> allMetricNames() {
    Map<NodeId, Set<String>> metricNameMap = Maps.newHashMap();
    Query query = new Query("SHOW MEASUREMENTS", database);
    List<QueryResult.Result> results = influxDB.query(query).getResults();
    List<List<Object>> rawMetricNames = results.get(0).getSeries().get(0).getValues();

    rawMetricNames.forEach(rawMetricName -> {
        String nodeIdStr = getNodeId(strip(rawMetricName.toString()));

        if (nodeIdStr != null) {
            NodeId nodeId = NodeId.nodeId(nodeIdStr);
            String metricName = getMetricName(strip(rawMetricName.toString()));

            if (!metricNameMap.containsKey(nodeId)) {
                metricNameMap.putIfAbsent(nodeId, Sets.newHashSet());
            }

            if (metricName != null) {
                metricNameMap.get(nodeId).add(metricName);
            }
        }
    });

    return metricNameMap;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:31,代码来源:DefaultInfluxDbMetricsRetriever.java

示例4: getFileSize

import org.influxdb.dto.QueryResult; //导入依赖的package包/类
@Override
public long getFileSize() {
    final QueryResult result = getInfluxDB().query(new Query(String.format("select sum(\"diskBytes\") as \"diskBytes\" from (select last(\"diskBytes\"::field) as \"diskBytes\" from \"shard\" where \"database\"::tag = '%s' group by * limit 1)", getDatabase().replace("'", "\\'")), "_internal"), TimeUnit.MILLISECONDS);
    throwOnResultError(result);
    return result.getResults().stream()
            .filter(r -> !r.hasError())
            .filter(r -> r.getSeries() != null)
            .flatMap(r -> r.getSeries().stream())
            .map(s -> getColumnFromSeries(s, "diskBytes"))
            .filter(Optional::isPresent)
            .flatMap(Optional::get)
            .map(Number.class::cast)
            .mapToLong(Number::longValue)
            .findAny()
            .orElse(0);
}
 
开发者ID:groupon,项目名称:monsoon,代码行数:17,代码来源:InfluxHistory.java

示例5: 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);
    });
}
 
开发者ID:groupon,项目名称:monsoon,代码行数:25,代码来源:SeriesHandler.java

示例6: keyedQueriesAnswer

import org.influxdb.dto.QueryResult; //导入依赖的package包/类
private static Answer<QueryResult> keyedQueriesAnswer(Collection<KeyedQuery> queries) {
    final Map<String, String> mapping = queries.stream().collect(Collectors.toMap(KeyedQuery::getQuery, KeyedQuery::getBaseFileName));

    return new Answer<QueryResult>() {
        @Override
        public QueryResult answer(InvocationOnMock invocation) throws Throwable {
            final String q = invocation.getArgumentAt(0, Query.class).getCommand();
            final String file = mapping.get(q);
            if (file != null) {
                LOG.log(Level.INFO, "mapping to \"{1}\" from query: {0}", new Object[]{q, file});
                return new JsonQueryResult(file).getQueryResult();
            }
            throw new AssertionError("unexpected query: " + q);
        }
    };
}
 
开发者ID:groupon,项目名称:monsoon,代码行数:17,代码来源:InfluxHistoryTest.java

示例7: executePrivilege

import org.influxdb.dto.QueryResult; //导入依赖的package包/类
protected QueryResult executePrivilege(String type, UserPrivilege privilege, String username, String database) throws InflowException {
  if (privilege != UserPrivilege.ALL && database == null) {
    throw new InflowException("Only grant ALL cluster-wide privileges are allowed");
  }

  String query = String.format("%s %s", type, privilege);

  if (database != null) {
    query += " ON " + database;
  } else {
    query += " PRIVILEGES ";
  }

  if (username != null) {
    if (type.equals("GRANT")) {
      query += "TO " + username;
    } else if (type.equals("REVOKE")) {
      query += "FROM " + username;
    }
  }
  
  logger.debug("Admin.executePrivilege() query = " + query);

  return this.client.query(null, query);
}
 
开发者ID:nkiraly,项目名称:influxdb-inflow,代码行数:26,代码来源:Admin.java

示例8: create

import org.influxdb.dto.QueryResult; //导入依赖的package包/类
/**
 * Create this database
 *
 * @param retentionPolicy
 * @param createIfNotExists Only create the database if it does not yet exist
 */
public QueryResult create(RetentionPolicy retentionPolicy, boolean createIfNotExists) throws InflowDatabaseException {
  QueryResult queryResult = null;
  try {
    String query = String.format(
            "CREATE DATABASE %s%s",
            (createIfNotExists ? "IF NOT EXISTS " : ""),
            this.name
    );

    queryResult = this.query(query);

    if (retentionPolicy != null) {
      this.createRetentionPolicy(retentionPolicy);
    }
  } catch (Exception ex) {
    throw new InflowDatabaseException("Failed to create database " + this.name + ": " + ex.getMessage(), ex);
  }
  return queryResult;
}
 
开发者ID:nkiraly,项目名称:influxdb-inflow,代码行数:26,代码来源:Database.java

示例9: 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
  );
}
 
开发者ID:nkiraly,项目名称:influxdb-inflow,代码行数:18,代码来源:ClientTest.java

示例10: getMockClientThatReturnsEmptyQueryResult

import org.influxdb.dto.QueryResult; //导入依赖的package包/类
public Client getMockClientThatReturnsEmptyQueryResult() throws Exception {
  Client client = this.getMockClient();

  // when calling query
  // with any parameters
  // return empty result data object
  Mockito.when(client.query(anyString(), anyString()))
          .thenAnswer(new Answer<QueryResult>() {
            @Override
            public QueryResult answer(InvocationOnMock invocation) throws Throwable {
              Object[] args = invocation.getArguments();
              if ( args[0] != null ) {
                String databaseName = args[0].toString();
              }
              if ( args[1] != null ) {
                Client.setLastQuery(args[1].toString());
              }
              return getEmptyQueryResult();
            }
          });

  return client;
}
 
开发者ID:nkiraly,项目名称:influxdb-inflow,代码行数:24,代码来源:AbstractTest.java

示例11: retrieveUsageRecordsForUser

import org.influxdb.dto.QueryResult; //导入依赖的package包/类
/**
 * Retrieve Usage Records for specified User, enabled meters and provided time window
 *
 * @param user
 * @param from
 * @param to
 * @param meters
 * @return UsageList object
 */
private UsageList retrieveUsageRecordsForUser(String user, String from, String to, List<String> meters) {
    UsageList list = new UsageList();

    // populate header
    list.setUserid(user);
    list.setTime(from, to);

    // go over all enabled meters
    for (String meter : meters) {

        // first construct required query
        String query = list.createQuery(user, from, to, meter);
        QueryResult result = dbClient.runQuery(query);
        list.addUsageFromMeter(result);
    }

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

示例12: 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

示例13: 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

示例14: metricsByName

import org.influxdb.dto.QueryResult; //导入依赖的package包/类
@Override
public Map<NodeId, List<InfluxMetric>> metricsByName(String metricName, int period,
                                               TimeUnit unit) {
    Map<NodeId, List<InfluxMetric>> map = Maps.newHashMap();
    List<InfluxMetric> metrics = Lists.newArrayList();
    String queryPrefix = new StringBuilder()
            .append("SELECT m1_rate FROM")
            .append(database)
            .append(METRIC_DELIMITER)
            .append(quote(DEFAULT_POLICY))
            .append(METRIC_DELIMITER)
            .toString();
    String querySuffix = new StringBuilder()
            .append(" WHERE time > now() - ")
            .append(period)
            .append(unitString(unit))
            .toString();

    allMetricNames().keySet().forEach(nodeId -> {
        String queryString = new StringBuilder()
                .append(queryPrefix)
                .append(quote(nodeId + METRIC_DELIMITER + metricName))
                .append(querySuffix)
                .toString();
        Query query = new Query(queryString, database);
        List<QueryResult.Result> results = influxDB.query(query).getResults();

        if (results != null && results.get(0) != null
                && results.get(0).getSeries() != null) {

            results.get(0).getSeries().get(0).getValues().forEach(value ->
                metrics.add(new DefaultInfluxMetric.Builder()
                        .time((String) value.get(0))
                        .oneMinRate((Double) value.get(1))
                        .build()));
            map.putIfAbsent(nodeId, metrics);
        }
    });

    return map;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:42,代码来源:DefaultInfluxDbMetricsRetriever.java

示例15: extractTimestamps

import org.influxdb.dto.QueryResult; //导入依赖的package包/类
protected static Stream<DateTime> extractTimestamps(QueryResult result) {
    return result.getResults().stream()
            .filter(resultEntry -> !resultEntry.hasError())
            .filter(resultEntry -> resultEntry.getSeries() != null)
            .flatMap(resultEntry -> resultEntry.getSeries().stream())
            .map(series -> getColumnFromSeries(series, TIME_COLUMN))
            .filter(Optional::isPresent)
            .flatMap(Optional::get)
            .map(Number.class::cast)
            .map(number -> new DateTime(number.longValue(), DateTimeZone.UTC));
}
 
开发者ID:groupon,项目名称:monsoon,代码行数:12,代码来源:InfluxUtil.java


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