本文整理了Java中org.influxdb.dto.Query
类的一些代码示例,展示了Query
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query
类的具体详情如下:
包路径:org.influxdb.dto.Query
类名称:Query
[英]Represents a Query against Influxdb.
[中]表示对XDB的查询。
代码示例来源: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: influxdata/influxdb-java
/**
* @return url encoded command
*/
public String getCommandWithUrlEncoded() {
return encode(command);
}
代码示例来源:origin: influxdata/influxdb-java
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
BoundParameterQuery other = (BoundParameterQuery) obj;
if (!params.equals(other.params)) {
return false;
}
return true;
}
代码示例来源:origin: influxdata/influxdb-java
/**
* Calls the influxDBService for the query.
*/
private Call<QueryResult> callQuery(final Query query) {
Call<QueryResult> call;
String db = query.getDatabase();
if (db == null) {
db = this.database;
}
if (query instanceof BoundParameterQuery) {
BoundParameterQuery boundParameterQuery = (BoundParameterQuery) query;
call = this.influxDBService.postQuery(db, query.getCommandWithUrlEncoded(),
boundParameterQuery.getParameterJsonWithUrlEncoded());
} else {
if (query.requiresPost()) {
call = this.influxDBService.postQuery(db, query.getCommandWithUrlEncoded());
} else {
call = this.influxDBService.query(db, query.getCommandWithUrlEncoded());
}
}
return call;
}
代码示例来源:origin: influxdata/influxdb-java
/**
* {@inheritDoc}
*/
@Override
public QueryResult query(final Query query, final TimeUnit timeUnit) {
Call<QueryResult> call = null;
if (query instanceof BoundParameterQuery) {
BoundParameterQuery boundParameterQuery = (BoundParameterQuery) query;
call = this.influxDBService.query(query.getDatabase(),
TimeUtil.toTimePrecision(timeUnit), query.getCommandWithUrlEncoded(),
boundParameterQuery.getParameterJsonWithUrlEncoded());
} else {
call = this.influxDBService.query(query.getDatabase(),
TimeUtil.toTimePrecision(timeUnit), query.getCommandWithUrlEncoded());
}
return executeQuery(call);
}
代码示例来源: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: org.influxdb/influxdb-java
/**
* Calls the influxDBService for the query.
*/
private Call<QueryResult> callQuery(final Query query) {
Call<QueryResult> call;
String db = query.getDatabase();
if (db == null) {
db = this.database;
}
if (query instanceof BoundParameterQuery) {
BoundParameterQuery boundParameterQuery = (BoundParameterQuery) query;
call = this.influxDBService.postQuery(db, query.getCommandWithUrlEncoded(),
boundParameterQuery.getParameterJsonWithUrlEncoded());
} else {
if (query.requiresPost()) {
call = this.influxDBService.postQuery(db, query.getCommandWithUrlEncoded());
} else {
call = this.influxDBService.query(db, query.getCommandWithUrlEncoded());
}
}
return call;
}
代码示例来源:origin: influxdata/influxdb-java
if (query instanceof BoundParameterQuery) {
BoundParameterQuery boundParameterQuery = (BoundParameterQuery) query;
call = this.influxDBService.query(query.getDatabase(), query.getCommandWithUrlEncoded(), chunkSize,
boundParameterQuery.getParameterJsonWithUrlEncoded());
} else {
call = this.influxDBService.query(query.getDatabase(), query.getCommandWithUrlEncoded(), chunkSize);
代码示例来源:origin: sitewhere/sitewhere
/**
* Search for of events of a given type associated with one or more entities for
* a given index.
*
* @param index
* @param entityIds
* @param type
* @param criteria
* @param client
* @param clazz
* @return
* @throws SiteWhereException
*/
public static <T> SearchResults<T> searchByIndex(DeviceEventIndex index, List<UUID> entityIds, DeviceEventType type,
ISearchCriteria criteria, InfluxDbClient client, Class<T> clazz) throws SiteWhereException {
Query query = InfluxDbDeviceEvent.queryEventsOfTypeForIndex(index, type, entityIds, criteria,
client.getDatabase().getValue());
LOGGER.debug("Query: " + query.getCommand());
QueryResult response = client.getInflux().query(query, TimeUnit.MILLISECONDS);
List<T> results = InfluxDbDeviceEvent.eventsOfType(response, clazz);
Query countQuery = InfluxDbDeviceEvent.queryEventsOfTypeForIndexCount(index, type, entityIds, criteria,
client.getDatabase().getValue());
LOGGER.debug("Count: " + countQuery.getCommand());
QueryResult countResponse = client.getInflux().query(countQuery);
long count = parseCount(countResponse);
return new SearchResults<T>(results, count);
}
代码示例来源: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: org.influxdb/influxdb-java
/**
* {@inheritDoc}
*/
@Override
public QueryResult query(final Query query, final TimeUnit timeUnit) {
Call<QueryResult> call = null;
if (query instanceof BoundParameterQuery) {
BoundParameterQuery boundParameterQuery = (BoundParameterQuery) query;
call = this.influxDBService.query(query.getDatabase(),
TimeUtil.toTimePrecision(timeUnit), query.getCommandWithUrlEncoded(),
boundParameterQuery.getParameterJsonWithUrlEncoded());
} else {
call = this.influxDBService.query(query.getDatabase(),
TimeUtil.toTimePrecision(timeUnit), query.getCommandWithUrlEncoded());
}
return executeQuery(call);
}
代码示例来源:origin: influxdata/influxdb-java
/**
* {@inheritDoc}
*/
@Override
public void deleteDatabase(final String name) {
executeQuery(this.influxDBService.postQuery(Query.encode("DROP DATABASE \"" + name + "\"")));
}
代码示例来源:origin: org.influxdb/influxdb-java
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
BoundParameterQuery other = (BoundParameterQuery) obj;
if (!params.equals(other.params)) {
return false;
}
return true;
}
代码示例来源: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: org.influxdb/influxdb-java
if (query instanceof BoundParameterQuery) {
BoundParameterQuery boundParameterQuery = (BoundParameterQuery) query;
call = this.influxDBService.query(query.getDatabase(), query.getCommandWithUrlEncoded(), chunkSize,
boundParameterQuery.getParameterJsonWithUrlEncoded());
} else {
call = this.influxDBService.query(query.getDatabase(), query.getCommandWithUrlEncoded(), chunkSize);
代码示例来源:origin: influxdata/influxdb-java
/**
* {@inheritDoc}
* @param rpName the name of the retentionPolicy
* @param database the name of the database
*/
@Override
public void dropRetentionPolicy(final String rpName, final String database) {
Preconditions.checkNonEmptyString(rpName, "retentionPolicyName");
Preconditions.checkNonEmptyString(database, "database");
StringBuilder queryBuilder = new StringBuilder("DROP RETENTION POLICY \"");
queryBuilder.append(rpName)
.append("\" ON \"")
.append(database)
.append("\"");
executeQuery(this.influxDBService.postQuery(Query.encode(queryBuilder.toString())));
}
代码示例来源:origin: sitewhere/sitewhere
/**
* Find the list of responses for a command invocation.
*
* @param originatingEventId
* @param database
* @return
* @throws SiteWhereException
*/
public static Query queryResponsesForInvocation(UUID originatingEventId, String database)
throws SiteWhereException {
return new Query("SELECT * FROM " + InfluxDbDeviceEvent.COLLECTION_EVENTS + " where type='"
+ DeviceEventType.CommandResponse + "' and " + InfluxDbDeviceCommandResponse.RSP_ORIGINATING_EVENT_ID
+ "='" + originatingEventId + "' GROUP BY " + InfluxDbDeviceEvent.EVENT_ASSIGNMENT
+ " ORDER BY time DESC", database);
}
代码示例来源:origin: influxdata/influxdb-java
/**
* {@inheritDoc}
*/
@Override
public void createDatabase(final String name) {
Preconditions.checkNonEmptyString(name, "name");
String createDatabaseQueryString = String.format("CREATE DATABASE \"%s\"", name);
executeQuery(this.influxDBService.postQuery(Query.encode(createDatabaseQueryString)));
}
代码示例来源:origin: sitewhere/sitewhere
/**
* Count number of response for a command invocation.
*
* @param originatingEventId
* @param database
* @return
* @throws SiteWhereException
*/
public static Query queryResponsesForInvocationCount(UUID originatingEventId, String database)
throws SiteWhereException {
return new Query("SELECT count(eid) FROM " + InfluxDbDeviceEvent.COLLECTION_EVENTS + " where type='"
+ DeviceEventType.CommandResponse + "' and " + InfluxDbDeviceCommandResponse.RSP_ORIGINATING_EVENT_ID
+ "='" + originatingEventId + "' GROUP BY " + InfluxDbDeviceEvent.EVENT_ASSIGNMENT, database);
}
}
代码示例来源:origin: influxdata/influxdb-java
queryBuilder.append(" DEFAULT");
executeQuery(this.influxDBService.postQuery(Query.encode(queryBuilder.toString())));
内容来源于网络,如有侵权,请联系作者删除!