org.influxdb.InfluxDB.query()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(286)

本文整理了Java中org.influxdb.InfluxDB.query()方法的一些代码示例,展示了InfluxDB.query()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。InfluxDB.query()方法的具体详情如下:
包路径:org.influxdb.InfluxDB
类名称:InfluxDB
方法名:query

InfluxDB.query介绍

[英]Execute a query against a database.
[中]对数据库执行查询。

代码示例

代码示例来源:origin: apache/nifi

protected List<QueryResult> executeQuery(final ProcessContext context, String database, String query, TimeUnit timeunit,
                     int chunkSize) throws InterruptedException {
  final CountDownLatch latch = new CountDownLatch(1);
  InfluxDB influx = getInfluxDB(context);
  Query influxQuery = new Query(query, database);
  if (chunkSize > 0) {
    List<QueryResult> results = new LinkedList<>();
    influx.query(influxQuery, chunkSize, result -> {
      if (isQueryDone(result.getError())) {
        latch.countDown();
      } else {
        results.add(result);
      }
    });
    latch.await();
    return results;
  } else {
    return Collections.singletonList(influx.query(influxQuery, timeunit));
  }
}

代码示例来源:origin: testcontainers/testcontainers-java

@Test
  public void queryForWriteAndRead() {
    InfluxDB influxDB = influxDBContainer.getNewInfluxDB();

    Point point = Point.measurement("cpu")
      .time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
      .addField("idle", 90L)
      .addField("user", 9L)
      .addField("system", 1L)
      .build();
    influxDB.write(point);

    Query query = new Query("SELECT idle FROM cpu", DATABASE);
    QueryResult actual = influxDB.query(query);

    assertThat(actual, notNullValue());
    assertThat(actual.getError(), nullValue());
    assertThat(actual.getResults(), notNullValue());
    assertThat(actual.getResults().size(), is(1));

  }
}

代码示例来源:origin: influxdata/influxdb-java

public <T> List<T> query(final Query query, final Class<T> clazz) {
 throwExceptionIfMissingAnnotation(clazz);
 QueryResult queryResult = influxDB.query(query);
 return toPOJO(queryResult, clazz);
}

代码示例来源:origin: influxdata/influxdb-java

public <T> List<T> query(final Class<T> clazz) {
 throwExceptionIfMissingAnnotation(clazz);
 String measurement = getMeasurementName(clazz);
 String database = getDatabaseName(clazz);
 if ("[unassigned]".equals(database)) {
  throw new IllegalArgumentException(
    Measurement.class.getSimpleName()
      + " of class "
      + clazz.getName()
      + " should specify a database value for this operation");
 }
 QueryResult queryResult = influxDB.query(new Query("SELECT * FROM " + measurement, database));
 return toPOJO(queryResult, clazz);
}

代码示例来源:origin: miwurster/spring-data-influxdb

@Override
public QueryResult query(final Query query, final TimeUnit timeUnit)
{
 return getConnection().query(query, timeUnit);
}

代码示例来源:origin: miwurster/spring-data-influxdb

@Override
public void query(Query query, int chunkSize, Consumer<QueryResult> consumer)
{
 getConnection().query(query, chunkSize, consumer);
}

代码示例来源:origin: org.apereo.cas/cas-server-support-influxdb-core

/**
 * Query result.
 *
 * @param fields      the fields
 * @param measurement the table
 * @param dbName      the db name
 * @return the query result
 */
public QueryResult query(final String fields, final String measurement, final String dbName) {
  val filter = String.format("SELECT %s FROM %s", fields, measurement);
  val query = new Query(filter, dbName);
  return this.influxDb.query(query);
}

代码示例来源:origin: miwurster/spring-data-influxdb

@Override
public QueryResult query(final Query query)
{
 return getConnection().query(query);
}

代码示例来源:origin: org.apache.camel/camel-influxdb

private void doQuery(Exchange exchange, String dataBaseName, String retentionPolicy) {
  String query = calculateQuery(exchange);
  Query influxdbQuery = new Query(query, dataBaseName);
  QueryResult resultSet = connection.query(influxdbQuery);
  MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
  exchange.getOut().setBody(resultSet);
}

代码示例来源:origin: inspectIT/inspectIT

/**
 * Executes the given query on the database.
 *
 * @param query
 *            the query to execute
 * @return the result of this query
 */
public QueryResult query(String query) {
  if ((query == null) || !isConnected()) {
    return null;
  }
  if (log.isDebugEnabled()) {
    log.debug("Execute query on InfluxDB: {}", query);
  }
  return influxDB.query(new Query(query, database));
}

代码示例来源:origin: org.influxdb/influxdb-java

public <T> List<T> query(final Query query, final Class<T> clazz) {
 throwExceptionIfMissingAnnotation(clazz);
 QueryResult queryResult = influxDB.query(query);
 return toPOJO(queryResult, clazz);
}

代码示例来源:origin: org.influxdb/influxdb-java

public <T> List<T> query(final Class<T> clazz) {
 throwExceptionIfMissingAnnotation(clazz);
 String measurement = getMeasurementName(clazz);
 String database = getDatabaseName(clazz);
 if ("[unassigned]".equals(database)) {
  throw new IllegalArgumentException(
    Measurement.class.getSimpleName()
      + " of class "
      + clazz.getName()
      + " should specify a database value for this operation");
 }
 QueryResult queryResult = influxDB.query(new Query("SELECT * FROM " + measurement, database));
 return toPOJO(queryResult, clazz);
}

代码示例来源:origin: inspectIT/inspectIT

/**
 * Executes a write operation to test the connection.
 *
 * @return <code>true</code> if the write operation was successful.
 */
private boolean executeWriteTest() {
  Point point = Point.measurement(DUMMY_MEASUREMENT).addField("write_check", true).build();
  try {
    influxDB.write(database, retentionPolicy, point);
    influxDB.query(new Query("DROP SERIES FROM " + DUMMY_MEASUREMENT, database));
  } catch (Exception ex) {
    if (log.isDebugEnabled()) {
      log.debug("Test-write failed with the following message: " + ex.getMessage());
    }
    return false;
  }
  return true;
}

代码示例来源:origin: sitewhere/sitewhere

/**
 * Get responses for a command invocation.
 * 
 * @param originatingEventId
 * @param influx
 * @param database
 * @return
 * @throws SiteWhereException
 */
public static SearchResults<IDeviceCommandResponse> getResponsesForInvocation(UUID originatingEventId,
  InfluxDB influx, String database) throws SiteWhereException {
Query query = queryResponsesForInvocation(originatingEventId, database);
QueryResult response = influx.query(query, TimeUnit.MILLISECONDS);
List<IDeviceCommandResponse> results = InfluxDbDeviceEvent.eventsOfType(response, IDeviceCommandResponse.class);
Query countQuery = queryResponsesForInvocationCount(originatingEventId, database);
QueryResult countResponse = influx.query(countQuery);
long count = InfluxDbDeviceEvent.parseCount(countResponse);
return new SearchResults<IDeviceCommandResponse>(results, count);
}

代码示例来源:origin: sitewhere/sitewhere

/**
 * Get an event by unique id.
 * 
 * @param eventId
 * @param client
 * @return
 * @throws SiteWhereException
 */
public static IDeviceEvent getEventById(UUID eventId, InfluxDbClient client) throws SiteWhereException {
Query query = new Query(
  "SELECT * FROM " + InfluxDbDeviceEvent.COLLECTION_EVENTS + " where " + EVENT_ID + "='" + eventId + "'",
  client.getDatabase().getValue());
QueryResult response = client.getInflux().query(query, TimeUnit.MILLISECONDS);
List<IDeviceEvent> results = InfluxDbDeviceEvent.eventsOfType(response, IDeviceEvent.class);
if (results.size() > 0) {
  return results.get(0);
}
return null;
}

代码示例来源:origin: inspectIT/inspectIT

@Test
public void enableInflux() {
  influxDao.active = true;
  influxDao.propertiesUpdated();
  assertThat(influxDao.isConnected(), is(true));
  assertThat(influxDao.getServiceType(), is(ExternalServiceType.INFLUXDB));
  assertThat(influxDao.getServiceStatus(), is(ExternalServiceStatus.CONNECTED));
  verify(executor, times(1)).submit(any(Runnable.class));
  verify(influxDb).ping();
  verify(influxDb).write(any(String.class), any(String.class), any(Point.class));
  verify(influxDb).query(any(Query.class));
  verify(influxDb).isBatchEnabled();
  verify(influxDb).enableBatch(InfluxDBDao.BATCH_BUFFER_SIZE, InfluxDBDao.BATCH_FLUSH_TIMER, TimeUnit.SECONDS);
  verify(availabilityChecker).deactivate();
  verify(availabilityChecker).setInflux(influxDb);
  verify(availabilityChecker).activate();
  verify(clientFactory).createClient();
  verifyNoMoreInteractions(influxDb, availabilityChecker, executor, clientFactory);
  verifyZeroInteractions(future);
}

代码示例来源:origin: inspectIT/inspectIT

@Test
public void executeNullQuery() {
  influxDao.active = true;
  influxDao.propertiesUpdated();
  influxDao.query(null);
  assertThat(influxDao.isConnected(), is(true));
  assertThat(influxDao.getServiceStatus(), is(ExternalServiceStatus.CONNECTED));
  verify(influxDb).ping();
  verify(influxDb).write(any(String.class), any(String.class), any(Point.class));
  verify(influxDb).isBatchEnabled();
  verify(influxDb).enableBatch(InfluxDBDao.BATCH_BUFFER_SIZE, InfluxDBDao.BATCH_FLUSH_TIMER, TimeUnit.SECONDS);
  verify(influxDb).query(any(Query.class));
  verify(executor).submit(any(Runnable.class));
  verify(availabilityChecker).deactivate();
  verify(availabilityChecker).setInflux(influxDb);
  verify(availabilityChecker).activate();
  verify(clientFactory).createClient();
  verifyNoMoreInteractions(clientFactory, availabilityChecker, executor, influxDb);
  verifyZeroInteractions(future);
}

代码示例来源:origin: inspectIT/inspectIT

@Test
public void executeQuery() {
  influxDao.active = true;
  influxDao.propertiesUpdated();
  influxDao.query("myQuery");
  assertThat(influxDao.isConnected(), is(true));
  assertThat(influxDao.getServiceStatus(), is(ExternalServiceStatus.CONNECTED));
  ArgumentCaptor<Query> queryCaptor = ArgumentCaptor.forClass(Query.class);
  verify(influxDb, times(2)).query(queryCaptor.capture());
  assertThat(queryCaptor.getValue().getCommand(), equalTo("myQuery"));
  verify(influxDb).ping();
  verify(influxDb).write(any(String.class), any(String.class), any(Point.class));
  verify(influxDb).isBatchEnabled();
  verify(influxDb).enableBatch(InfluxDBDao.BATCH_BUFFER_SIZE, InfluxDBDao.BATCH_FLUSH_TIMER, TimeUnit.SECONDS);
  verify(executor).submit(any(Runnable.class));
  verify(availabilityChecker).deactivate();
  verify(availabilityChecker).setInflux(influxDb);
  verify(availabilityChecker).activate();
  verify(clientFactory).createClient();
  verifyNoMoreInteractions(clientFactory, availabilityChecker, executor, influxDb);
  verifyZeroInteractions(future);
}

代码示例来源:origin: inspectIT/inspectIT

@Test
public void enableInfluxDatabaseExists() {
  influxDao.active = true;
  when(influxDb.describeDatabases()).thenReturn(Arrays.asList(influxDao.database));
  influxDao.propertiesUpdated();
  assertThat(influxDao.isConnected(), is(true));
  assertThat(influxDao.getServiceStatus(), is(ExternalServiceStatus.CONNECTED));
  verify(executor, times(1)).submit(any(Runnable.class));
  verify(influxDb).ping();
  verify(influxDb).write(any(String.class), any(String.class), any(Point.class));
  verify(influxDb).query(any(Query.class));
  verify(influxDb).isBatchEnabled();
  verify(influxDb).enableBatch(InfluxDBDao.BATCH_BUFFER_SIZE, InfluxDBDao.BATCH_FLUSH_TIMER, TimeUnit.SECONDS);
  verify(availabilityChecker).deactivate();
  verify(availabilityChecker).setInflux(influxDb);
  verify(availabilityChecker).activate();
  verify(clientFactory).createClient();
  verifyNoMoreInteractions(influxDb, availabilityChecker, executor, clientFactory);
  verifyZeroInteractions(future);
}

代码示例来源:origin: inspectIT/inspectIT

@Test
@SuppressWarnings("unchecked")
public void enableInfluxButNotAvailable() {
  influxDao.active = true;
  when(influxDb.ping()).thenThrow(Exception.class);
  influxDao.propertiesUpdated();
  assertThat(influxDao.isConnected(), is(false));
  assertThat(influxDao.getServiceStatus(), is(ExternalServiceStatus.DISCONNECTED));
  verify(executor, times(1)).submit(any(Runnable.class));
  verify(influxDb).ping();
  verify(influxDb).write(any(String.class), any(String.class), any(Point.class));
  verify(influxDb).query(any(Query.class));
  verify(influxDb).isBatchEnabled();
  verify(influxDb).enableBatch(InfluxDBDao.BATCH_BUFFER_SIZE, InfluxDBDao.BATCH_FLUSH_TIMER, TimeUnit.SECONDS);
  verify(availabilityChecker).deactivate();
  verify(availabilityChecker).setInflux(influxDb);
  verify(availabilityChecker).activate();
  verify(clientFactory).createClient();
  verifyNoMoreInteractions(influxDb, availabilityChecker, executor, clientFactory);
  verifyZeroInteractions(future);
}

相关文章