Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InfluxDBMapper.toPOJO() bug? #834

Open
trdmm opened this issue May 24, 2022 · 5 comments
Open

InfluxDBMapper.toPOJO() bug? #834

trdmm opened this issue May 24, 2022 · 5 comments

Comments

@trdmm
Copy link

trdmm commented May 24, 2022

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?

@majst01
Copy link
Collaborator

majst01 commented May 24, 2022

But this parses to the same timestamp, right

@trdmm
Copy link
Author

trdmm commented May 24, 2022

But this parses to the same timestamp, right

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

@majst01
Copy link
Collaborator

majst01 commented May 24, 2022

Can you write a Unit test which demonstrates this BUG please

@trdmm
Copy link
Author

trdmm commented May 24, 2022

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.

@majst01
Copy link
Collaborator

majst01 commented May 24, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants