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 | 17 | |
18 | 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 | 21 | "&& '${spring.jpa.database-platform}'=='org.hibernate.dialect.PostgreSQLDialect'") |
22 | 22 | public @interface PsqlTsAnyDao { |
23 | 23 | } | ... | ... |
... | ... | @@ -46,6 +46,8 @@ import org.thingsboard.server.dao.util.SqlTsDao; |
46 | 46 | import java.time.Instant; |
47 | 47 | import java.time.LocalDateTime; |
48 | 48 | import java.time.ZoneOffset; |
49 | +import java.time.ZonedDateTime; | |
50 | +import java.time.format.DateTimeFormatter; | |
49 | 51 | import java.util.ArrayList; |
50 | 52 | import java.util.List; |
51 | 53 | import java.util.Optional; |
... | ... | @@ -298,13 +300,15 @@ public class JpaPsqlTimeseriesDao extends AbstractSimpleSqlTimeseriesDao<TsKvEnt |
298 | 300 | } |
299 | 301 | |
300 | 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 | 304 | return new PsqlPartition(toMills(EPOCH_START), Long.MAX_VALUE, tsFormat.getPattern()); |
305 | 305 | } else { |
306 | + LocalDateTime time = LocalDateTime.ofInstant(Instant.ofEpochMilli(ts), ZoneOffset.UTC); | |
307 | + LocalDateTime localDateTimeStart = tsFormat.trancateTo(time); | |
306 | 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 | 17 | |
18 | 18 | import lombok.Data; |
19 | 19 | |
20 | -import java.text.SimpleDateFormat; | |
21 | -import java.util.Date; | |
22 | - | |
23 | 20 | @Data |
24 | 21 | public class PsqlPartition { |
25 | 22 | |
... | ... | @@ -30,10 +27,10 @@ public class PsqlPartition { |
30 | 27 | private String partitionDate; |
31 | 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 | 31 | this.start = start; |
35 | 32 | this.end = end; |
36 | - this.partitionDate = new SimpleDateFormat(pattern).format(new Date(start)); | |
33 | + this.partitionDate = partitionDate; | |
37 | 34 | this.query = createStatement(start, end, partitionDate); |
38 | 35 | } |
39 | 36 | ... | ... |