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

Type conversion exception

Open LMH269084857 opened this issue 4 years ago • 13 comments

A field is an Integer in the database, but it is a Double value when it is retrieved

LMH269084857 avatar Dec 02 '21 01:12 LMH269084857

YES!, this is happening to me as well. I have the latest version installed (2.22)

When I use chronograf and look at the data it is indeed of type integer but has a value of decimal, which means it's being written to the db that way (instead of converted afterwards during a query)

FWIW I'm creating the record using line protocol:

this.influxDb.write(myInfluxDbName, null, ConsistencyLevel.ANY, myLineProtocolData);

I am also dynamically creating this on the fly via the line of code shown above. In other words, I did not create the measurement on startup/creation before running the above line of code.

As a temp workaround I am casting the result from double to int, but I shouldnt have to be doing that

UglyHobbitFeet avatar Jan 25 '22 18:01 UglyHobbitFeet

Not sure if this is the reason, but it looks like it might be why (Line 157) https://github.com/influxdata/influxdb-java/blob/master/src/main/java/org/influxdb/dto/Point.java#L157

UglyHobbitFeet avatar Jan 25 '22 18:01 UglyHobbitFeet

Not sure if this is the reason, but it looks like it might be why (Line 157) https://github.com/influxdata/influxdb-java/blob/master/src/main/java/org/influxdb/dto/Point.java#L157

Yes, I've tried other types of integer data. It does convert all integer data to double

LMH269084857 avatar Jan 26 '22 02:01 LMH269084857

@majst01 We appreciate your hard work with this package but this has been a major blocker for a while now! Will you be able to fix this in your next release and if so, do you have a rough estimate of when that will be? Thanks!

UglyHobbitFeet avatar Mar 15 '22 13:03 UglyHobbitFeet

If someone is willing to look deeper into the the root cause of this i will review any PR.

majst01 avatar Mar 15 '22 13:03 majst01

@majst01 I already did. It's mentioned on this thread a few comments up :)

UglyHobbitFeet avatar Mar 15 '22 13:03 UglyHobbitFeet

Sure, this is the why, but whats the solution ?

majst01 avatar Mar 15 '22 13:03 majst01

@majst01 To change "value = ((Integer) value).doubleValue()"; to "value = ((Integer) value)";

UglyHobbitFeet avatar Mar 15 '22 14:03 UglyHobbitFeet

@majst01 To change "value = ((Integer) value).doubleValue()"; to "value = ((Integer) value)";

Fine, write a PR and make all unit tests pass again

majst01 avatar Mar 15 '22 14:03 majst01

@majst01 Unfortunately I don't know how to do that. I'm not a big githubber sorry

UglyHobbitFeet avatar Mar 15 '22 14:03 UglyHobbitFeet

@majst01 Unfortunately I don't know how to do that. I'm not a big githubber sorry

https://jarv.is/notes/how-to-pull-request-fork-github/

majst01 avatar Mar 15 '22 14:03 majst01

@majst Thanks for that link. How do I 'make sure all unit tests pass again'

this is a maven project, an with the given shell script compile-and-tst.sh the whole project is compiled and all unit and integration tests are executed. as Described here https://github.com/influxdata/influxdb-java#contribute

UglyHobbitFeet avatar Mar 15 '22 14:03 UglyHobbitFeet

@majst01 I appreciate the links. I tried but unfortunately I shouldn't be the one doing PR as I'm not familiar enough with the overall codebase and the impact of changing existing test cases. I may end up messing a useful test case to 'fit' my fix. I know what the problem is and have pointed to the line of code that is causing it... that's the best I can do.

UglyHobbitFeet avatar Mar 15 '22 15:03 UglyHobbitFeet