Commit 384ce7424ca6c0a993d82b464e5568642d0f04ca
Committed by
Andrew Shvayka
1 parent
2dd2e6f6
Fix for query timeseries order by
Showing
2 changed files
with
54 additions
and
1 deletions
@@ -170,7 +170,7 @@ public class BaseTimeseriesService implements TimeseriesService { | @@ -170,7 +170,7 @@ public class BaseTimeseriesService implements TimeseriesService { | ||
170 | } else { | 170 | } else { |
171 | endTs = query.getEndTs(); | 171 | endTs = query.getEndTs(); |
172 | } | 172 | } |
173 | - return new BaseReadTsKvQuery(query.getKey(), startTs, endTs, query.getInterval(), query.getLimit(), query.getAggregation()); | 173 | + return new BaseReadTsKvQuery(query.getKey(), startTs, endTs, query.getInterval(), query.getLimit(), query.getAggregation(), query.getOrderBy()); |
174 | }).collect(Collectors.toList()); | 174 | }).collect(Collectors.toList()); |
175 | } | 175 | } |
176 | 176 |
@@ -31,6 +31,7 @@ import org.thingsboard.server.common.data.kv.BooleanDataEntry; | @@ -31,6 +31,7 @@ import org.thingsboard.server.common.data.kv.BooleanDataEntry; | ||
31 | import org.thingsboard.server.common.data.kv.DoubleDataEntry; | 31 | import org.thingsboard.server.common.data.kv.DoubleDataEntry; |
32 | import org.thingsboard.server.common.data.kv.KvEntry; | 32 | import org.thingsboard.server.common.data.kv.KvEntry; |
33 | import org.thingsboard.server.common.data.kv.LongDataEntry; | 33 | import org.thingsboard.server.common.data.kv.LongDataEntry; |
34 | +import org.thingsboard.server.common.data.kv.ReadTsKvQuery; | ||
34 | import org.thingsboard.server.common.data.kv.StringDataEntry; | 35 | import org.thingsboard.server.common.data.kv.StringDataEntry; |
35 | import org.thingsboard.server.common.data.kv.TsKvEntry; | 36 | import org.thingsboard.server.common.data.kv.TsKvEntry; |
36 | import org.thingsboard.server.common.data.objects.TelemetryEntityView; | 37 | import org.thingsboard.server.common.data.objects.TelemetryEntityView; |
@@ -149,6 +150,58 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest { | @@ -149,6 +150,58 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest { | ||
149 | } | 150 | } |
150 | 151 | ||
151 | @Test | 152 | @Test |
153 | + public void testFindByQueryAscOrder() throws Exception { | ||
154 | + DeviceId deviceId = new DeviceId(UUIDs.timeBased()); | ||
155 | + | ||
156 | + saveEntries(deviceId, TS - 2); | ||
157 | + saveEntries(deviceId, TS - 1); | ||
158 | + saveEntries(deviceId, TS); | ||
159 | + | ||
160 | + List<ReadTsKvQuery> queries = new ArrayList<>(); | ||
161 | + queries.add(new BaseReadTsKvQuery(STRING_KEY, TS - 3, TS, 0, 1000, Aggregation.NONE, "ASC")); | ||
162 | + | ||
163 | + List<TsKvEntry> entries = tsService.findAll(tenantId, deviceId, queries).get(); | ||
164 | + Assert.assertEquals(3, entries.size()); | ||
165 | + Assert.assertEquals(toTsEntry(TS - 2, stringKvEntry), entries.get(0)); | ||
166 | + Assert.assertEquals(toTsEntry(TS - 1, stringKvEntry), entries.get(1)); | ||
167 | + Assert.assertEquals(toTsEntry(TS, stringKvEntry), entries.get(2)); | ||
168 | + | ||
169 | + EntityView entityView = saveAndCreateEntityView(deviceId, Arrays.asList(STRING_KEY)); | ||
170 | + | ||
171 | + entries = tsService.findAll(tenantId, entityView.getId(), queries).get(); | ||
172 | + Assert.assertEquals(3, entries.size()); | ||
173 | + Assert.assertEquals(toTsEntry(TS - 2, stringKvEntry), entries.get(0)); | ||
174 | + Assert.assertEquals(toTsEntry(TS - 1, stringKvEntry), entries.get(1)); | ||
175 | + Assert.assertEquals(toTsEntry(TS, stringKvEntry), entries.get(2)); | ||
176 | + } | ||
177 | + | ||
178 | + @Test | ||
179 | + public void testFindByQueryDescOrder() throws Exception { | ||
180 | + DeviceId deviceId = new DeviceId(UUIDs.timeBased()); | ||
181 | + | ||
182 | + saveEntries(deviceId, TS - 2); | ||
183 | + saveEntries(deviceId, TS - 1); | ||
184 | + saveEntries(deviceId, TS); | ||
185 | + | ||
186 | + List<ReadTsKvQuery> queries = new ArrayList<>(); | ||
187 | + queries.add(new BaseReadTsKvQuery(STRING_KEY, TS - 3, TS, 0, 1000, Aggregation.NONE, "DESC")); | ||
188 | + | ||
189 | + List<TsKvEntry> entries = tsService.findAll(tenantId, deviceId, queries).get(); | ||
190 | + Assert.assertEquals(3, entries.size()); | ||
191 | + Assert.assertEquals(toTsEntry(TS, stringKvEntry), entries.get(0)); | ||
192 | + Assert.assertEquals(toTsEntry(TS - 1, stringKvEntry), entries.get(1)); | ||
193 | + Assert.assertEquals(toTsEntry(TS - 2, stringKvEntry), entries.get(2)); | ||
194 | + | ||
195 | + EntityView entityView = saveAndCreateEntityView(deviceId, Arrays.asList(STRING_KEY)); | ||
196 | + | ||
197 | + entries = tsService.findAll(tenantId, entityView.getId(), queries).get(); | ||
198 | + Assert.assertEquals(3, entries.size()); | ||
199 | + Assert.assertEquals(toTsEntry(TS, stringKvEntry), entries.get(0)); | ||
200 | + Assert.assertEquals(toTsEntry(TS - 1, stringKvEntry), entries.get(1)); | ||
201 | + Assert.assertEquals(toTsEntry(TS - 2, stringKvEntry), entries.get(2)); | ||
202 | + } | ||
203 | + | ||
204 | + @Test | ||
152 | public void testDeleteDeviceTsDataWithoutOverwritingLatest() throws Exception { | 205 | public void testDeleteDeviceTsDataWithoutOverwritingLatest() throws Exception { |
153 | DeviceId deviceId = new DeviceId(UUIDs.timeBased()); | 206 | DeviceId deviceId = new DeviceId(UUIDs.timeBased()); |
154 | 207 |