influxdb-java icon indicating copy to clipboard operation
influxdb-java copied to clipboard

InfluxDBMapper.toPOJO() bug?

Open trdmm opened this issue 3 years ago • 5 comments

When call InfluxDBMapper.toPOJO() , if the time field type is String and the millisecond value is an integer multiple of ten, it miss the last zero. Such as: If the timestamp is 1653354743560, the result is 2022-05-24T01:12:23.56Z, it should be 2022-05-24T01:12:23.560Z?

trdmm avatar May 24 '22 05:05 trdmm

But this parses to the same timestamp, right

majst01 avatar May 24 '22 05:05 majst01

But this parses to the same timestamp, right

I use TimeUtil.fromInfluxDBTimeFormat(2022-05-24T01:12:23.56Z), the result is 1653354743056 :cry:

trdmm avatar May 24 '22 05:05 trdmm

Can you write a Unit test which demonstrates this BUG please

majst01 avatar May 24 '22 05:05 majst01

Can you write a Unit test which demonstrates this BUG please

OutGzjLocation:

@Data
public class OutGzjLocation {
    @TimeColumn
    @Column(name = "time")
    private String time;
    /** imgID */
    @Column(name = "imgId")
    private int imgId = -1;
}

OutGzjLocationAnother:

    @TimeColumn
    @Column(name = "time")
    private Instant time;
    /** imgID */
    @Column(name = "imgId")
    private int imgId = -1;
SelectQueryImpl query = select().from(ConstantInfluxdb.targetDatabase, "\"10602ef9\"");

QueryResult queryResult = targetInfluxDB.query(query);

// time type is String
List<OutGzjLocation> outGzjLocations = targetInfluxDBMapper.toPOJO(queryResult, OutGzjLocation.class, "10602ef9");
// time type is Instant
List<OutGzjLocationAnother> outGzjLocationAnothers = targetInfluxDBMapper.toPOJO(queryResult, OutGzjLocationAnother.class, "10602ef9");

log.info("======time type is String======");
outGzjLocations.forEach(outGzjLocation -> {
    int imgId = outGzjLocation.getImgId();
    String timeStr = outGzjLocation.getTime();
    if (imgId == 14 || imgId == 15){
        long timestamp = TimeUtil.fromInfluxDBTimeFormat(timeStr);
        log.info("Time str: {}, timestamp: {}, imgId: {}.", timeStr, timestamp,imgId);
    }
});

log.info("======time type is Instant======");
outGzjLocationAnothers.forEach(outGzjLocationAnother -> {
    Instant instant = outGzjLocationAnother.getTime();
    int imgId = outGzjLocationAnother.getImgId();
    if (imgId == 14 || imgId == 15){
        log.info("Time str: {}, timestamp: {}, imgId: {}.", instant.toString(), instant.toEpochMilli(),imgId);
    }
});

The result is:

======time type is String======
Time str: 2022-05-23T12:08:20.56Z, timestamp: 1653307700056, imgId: 14.
Time str: 2022-05-23T12:08:22.56Z, timestamp: 1653307702056, imgId: 15.
======time type is Instant======
Time str: 2022-05-23T12:08:20.560Z, timestamp: 1653307700560, imgId: 14.
Time str: 2022-05-23T12:08:22.560Z, timestamp: 1653307702560, imgId: 15.

trdmm avatar May 24 '22 06:05 trdmm

Hi, nice, i mean as a Pull Request referring this Issue

majst01 avatar May 24 '22 06:05 majst01