Search in sources :

Example 11 with ReadTsKvQuery

use of org.thingsboard.server.common.data.kv.ReadTsKvQuery in project thingsboard by thingsboard.

the class SqlTimeseriesLatestDao method findNewLatestEntryFuture.

private ListenableFuture<List<TsKvEntry>> findNewLatestEntryFuture(TenantId tenantId, EntityId entityId, DeleteTsKvQuery query) {
    long startTs = 0;
    long endTs = query.getStartTs() - 1;
    ReadTsKvQuery findNewLatestQuery = new BaseReadTsKvQuery(query.getKey(), startTs, endTs, endTs - startTs, 1, Aggregation.NONE, DESC_ORDER);
    return aggregationTimeseriesDao.findAllAsync(tenantId, entityId, findNewLatestQuery);
}
Also used : BaseReadTsKvQuery(org.thingsboard.server.common.data.kv.BaseReadTsKvQuery) ReadTsKvQuery(org.thingsboard.server.common.data.kv.ReadTsKvQuery) BaseReadTsKvQuery(org.thingsboard.server.common.data.kv.BaseReadTsKvQuery)

Example 12 with ReadTsKvQuery

use of org.thingsboard.server.common.data.kv.ReadTsKvQuery in project thingsboard by thingsboard.

the class BaseTimeseriesServiceTest method testFindByQueryDescOrder.

@Test
public void testFindByQueryDescOrder() throws Exception {
    DeviceId deviceId = new DeviceId(Uuids.timeBased());
    saveEntries(deviceId, TS - 3);
    saveEntries(deviceId, TS - 2);
    saveEntries(deviceId, TS - 1);
    List<ReadTsKvQuery> queries = new ArrayList<>();
    queries.add(new BaseReadTsKvQuery(STRING_KEY, TS - 3, TS, 0, 1000, Aggregation.NONE, "DESC"));
    List<TsKvEntry> entries = tsService.findAll(tenantId, deviceId, queries).get(MAX_TIMEOUT, TimeUnit.SECONDS);
    Assert.assertEquals(3, entries.size());
    Assert.assertEquals(toTsEntry(TS - 1, stringKvEntry), entries.get(0));
    Assert.assertEquals(toTsEntry(TS - 2, stringKvEntry), entries.get(1));
    Assert.assertEquals(toTsEntry(TS - 3, stringKvEntry), entries.get(2));
    EntityView entityView = saveAndCreateEntityView(deviceId, Arrays.asList(STRING_KEY));
    entries = tsService.findAll(tenantId, entityView.getId(), queries).get(MAX_TIMEOUT, TimeUnit.SECONDS);
    Assert.assertEquals(3, entries.size());
    Assert.assertEquals(toTsEntry(TS - 1, stringKvEntry), entries.get(0));
    Assert.assertEquals(toTsEntry(TS - 2, stringKvEntry), entries.get(1));
    Assert.assertEquals(toTsEntry(TS - 3, stringKvEntry), entries.get(2));
}
Also used : BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) BaseReadTsKvQuery(org.thingsboard.server.common.data.kv.BaseReadTsKvQuery) ReadTsKvQuery(org.thingsboard.server.common.data.kv.ReadTsKvQuery) TelemetryEntityView(org.thingsboard.server.common.data.objects.TelemetryEntityView) EntityView(org.thingsboard.server.common.data.EntityView) DeviceId(org.thingsboard.server.common.data.id.DeviceId) ArrayList(java.util.ArrayList) BaseReadTsKvQuery(org.thingsboard.server.common.data.kv.BaseReadTsKvQuery) AbstractServiceTest(org.thingsboard.server.dao.service.AbstractServiceTest) Test(org.junit.Test)

Aggregations

BaseReadTsKvQuery (org.thingsboard.server.common.data.kv.BaseReadTsKvQuery)12 ReadTsKvQuery (org.thingsboard.server.common.data.kv.ReadTsKvQuery)12 TsKvEntry (org.thingsboard.server.common.data.kv.TsKvEntry)10 ArrayList (java.util.ArrayList)9 List (java.util.List)8 Futures (com.google.common.util.concurrent.Futures)7 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)7 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)7 Collectors (java.util.stream.Collectors)7 Slf4j (lombok.extern.slf4j.Slf4j)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 TenantId (org.thingsboard.server.common.data.id.TenantId)7 FutureCallback (com.google.common.util.concurrent.FutureCallback)5 Collections (java.util.Collections)5 EntityView (org.thingsboard.server.common.data.EntityView)5 TimeseriesService (org.thingsboard.server.dao.timeseries.TimeseriesService)5 Function (com.google.common.base.Function)4 TimeUnit (java.util.concurrent.TimeUnit)4 Nullable (javax.annotation.Nullable)4 Value (org.springframework.beans.factory.annotation.Value)4