Commit 41cbdd154e4a5b7e4387387b76d1aa043cdc4099
Committed by
Andrew Shvayka
1 parent
e3b39bed
fixed the partion date extracting
Showing
4 changed files
with
12 additions
and
11 deletions
@@ -17,7 +17,7 @@ package org.thingsboard.server.dao.util; | @@ -17,7 +17,7 @@ package org.thingsboard.server.dao.util; | ||
17 | 17 | ||
18 | import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | 18 | import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
19 | 19 | ||
20 | -@ConditionalOnExpression("('${database.ts.type}'=='sql' || '${database.entities.type}'=='timescale') " + | 20 | +@ConditionalOnExpression("('${database.ts.type}'=='sql' || '${database.ts.type}'=='timescale') " + |
21 | "&& '${spring.jpa.database-platform}'=='org.hibernate.dialect.PostgreSQLDialect'") | 21 | "&& '${spring.jpa.database-platform}'=='org.hibernate.dialect.PostgreSQLDialect'") |
22 | public @interface PsqlTsAnyDao { | 22 | public @interface PsqlTsAnyDao { |
23 | } | 23 | } |
@@ -46,6 +46,8 @@ import org.thingsboard.server.dao.util.SqlTsDao; | @@ -46,6 +46,8 @@ import org.thingsboard.server.dao.util.SqlTsDao; | ||
46 | import java.time.Instant; | 46 | import java.time.Instant; |
47 | import java.time.LocalDateTime; | 47 | import java.time.LocalDateTime; |
48 | import java.time.ZoneOffset; | 48 | import java.time.ZoneOffset; |
49 | +import java.time.ZonedDateTime; | ||
50 | +import java.time.format.DateTimeFormatter; | ||
49 | import java.util.ArrayList; | 51 | import java.util.ArrayList; |
50 | import java.util.List; | 52 | import java.util.List; |
51 | import java.util.Optional; | 53 | import java.util.Optional; |
@@ -298,13 +300,15 @@ public class JpaPsqlTimeseriesDao extends AbstractSimpleSqlTimeseriesDao<TsKvEnt | @@ -298,13 +300,15 @@ public class JpaPsqlTimeseriesDao extends AbstractSimpleSqlTimeseriesDao<TsKvEnt | ||
298 | } | 300 | } |
299 | 301 | ||
300 | private PsqlPartition toPartition(long ts) { | 302 | private PsqlPartition toPartition(long ts) { |
301 | - LocalDateTime time = LocalDateTime.ofInstant(Instant.ofEpochMilli(ts), ZoneOffset.UTC); | ||
302 | - LocalDateTime localDateTimeStart = tsFormat.trancateTo(time); | ||
303 | - if (localDateTimeStart == SqlTsPartitionDate.EPOCH_START) { | 303 | + if (tsFormat.getTruncateUnit().equals(SqlTsPartitionDate.INDEFINITE.getTruncateUnit())) { |
304 | return new PsqlPartition(toMills(EPOCH_START), Long.MAX_VALUE, tsFormat.getPattern()); | 304 | return new PsqlPartition(toMills(EPOCH_START), Long.MAX_VALUE, tsFormat.getPattern()); |
305 | } else { | 305 | } else { |
306 | + LocalDateTime time = LocalDateTime.ofInstant(Instant.ofEpochMilli(ts), ZoneOffset.UTC); | ||
307 | + LocalDateTime localDateTimeStart = tsFormat.trancateTo(time); | ||
306 | LocalDateTime localDateTimeEnd = tsFormat.plusTo(localDateTimeStart); | 308 | LocalDateTime localDateTimeEnd = tsFormat.plusTo(localDateTimeStart); |
307 | - return new PsqlPartition(toMills(localDateTimeStart), toMills(localDateTimeEnd), tsFormat.getPattern()); | 309 | + ZonedDateTime zonedDateTime = localDateTimeStart.atZone(ZoneOffset.UTC); |
310 | + String partitionDate = zonedDateTime.format(DateTimeFormatter.ofPattern(tsFormat.getPattern())); | ||
311 | + return new PsqlPartition(toMills(localDateTimeStart), toMills(localDateTimeEnd), partitionDate); | ||
308 | } | 312 | } |
309 | } | 313 | } |
310 | 314 |
@@ -17,9 +17,6 @@ package org.thingsboard.server.dao.timeseries; | @@ -17,9 +17,6 @@ package org.thingsboard.server.dao.timeseries; | ||
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | 19 | ||
20 | -import java.text.SimpleDateFormat; | ||
21 | -import java.util.Date; | ||
22 | - | ||
23 | @Data | 20 | @Data |
24 | public class PsqlPartition { | 21 | public class PsqlPartition { |
25 | 22 | ||
@@ -30,10 +27,10 @@ public class PsqlPartition { | @@ -30,10 +27,10 @@ public class PsqlPartition { | ||
30 | private String partitionDate; | 27 | private String partitionDate; |
31 | private String query; | 28 | private String query; |
32 | 29 | ||
33 | - public PsqlPartition(long start, long end, String pattern) { | 30 | + public PsqlPartition(long start, long end, String partitionDate) { |
34 | this.start = start; | 31 | this.start = start; |
35 | this.end = end; | 32 | this.end = end; |
36 | - this.partitionDate = new SimpleDateFormat(pattern).format(new Date(start)); | 33 | + this.partitionDate = partitionDate; |
37 | this.query = createStatement(start, end, partitionDate); | 34 | this.query = createStatement(start, end, partitionDate); |
38 | } | 35 | } |
39 | 36 |