Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Fix for AssetDatapointService query

Michael Rademakerc70cf7cccf17
diff --git a/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java b/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java
index bf333cc73..77ab6b7e0 100644
--- a/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java
+++ b/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java
@@ -260,11 +260,11 @@ public class AssetDatapointService implements ContainerService, AssetUpdateProce
if (downsample) {
// TODO: Change this to use something like this max min decimation algorithm https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019YLKSA2&l=en-GB)
- query.append("select TS as X, coalesce(AVG_VALUE, null) as Y " +
+ query.append("select PERIOD.TS as X, coalesce(AVG_VALUE, null) as Y " +
" from ( " +
" select date_trunc(?, GS)::timestamp TS " +
" from generate_series(to_timestamp(?), to_timestamp(?), ?) GS " +
- " ) TS " +
+ " ) PERIOD " +
" left join ( " +
" select " +
" date_trunc(?, TIMESTAMP)::timestamp as TS, ");
@@ -283,8 +283,8 @@ public class AssetDatapointService implements ContainerService, AssetUpdateProce
" and " +
" ENTITY_ID = ? and ATTRIBUTE_NAME = ? " +
" group by TS " +
- " ) DP using (TS) " +
- " order by TS asc "
+ " ) DP on DP.TS >= PERIOD.TS and DP.TS < PERIOD.TS + ? " +
+ " order by PERIOD.TS asc "
);
} else {
query.append("select distinct TIMESTAMP AS X, value AS Y from ASSET_DATAPOINT " +
@@ -311,6 +311,7 @@ public class AssetDatapointService implements ContainerService, AssetUpdateProce
st.setLong(7, toTimestampSeconds);
st.setString(8, attributeRef.getEntityId());
st.setString(9, attributeRef.getAttributeName());
+ st.setObject(10, new PGInterval(interval));
} else {
st.setLong(1, fromTimestampSeconds);
st.setLong(2, toTimestampSeconds);