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
[mongodb] persistence query gives ClassCastException for QuantityTypes #16308
Comments
Just trying to fix this bug and figured out, that the driver is still 2.3.1 from 2015 so in order to create some unittests, to properly fix this bug. I need to implement this #16310 as well. At least with the 4.4 driver. |
You should fix it in both, so that |
Upgrading such an old driver sounds good. Do you know if it is backward compatible, so older versions of MongoDB can still be used? |
Would do similar to the influxdb implementation. |
@J-N-K Just did a quick check. When we use the latest Java Sync driver (4.11) we would support all MongoDB versions down to 3.6 see the Compatibility So I recommend to use 4.11. Let's see whether I get some tests implemented as well ;-) |
@J-N-K Before I search too long - I've updated the driver and get this at the end of the build:
I could not find where to adjust the package dependencies further. Do you have any hint? |
How did you update the driver? As the latest version on maven is 3.12.14 Newer versions are listed under a different package name: mongodb-driver-sync When you update the pom.xml it should work, you only have to fix the build errors by adapting the code :-)
|
As mentioned there we have to go to https://mvnrepository.com/artifact/org.mongodb/mongodb-driver-sync for the later version. The build and test is successfull, but the last step fails. |
I can't reproduce that error as with the changed pom.xml it builds up to the part that it fails because some Types do not exist, and that is expected with such a verison bumb. No issue with dependencies. |
org.mongodb/mongodb-driver-sync/4.11.1 seems to be the correct artifact. Maybe you need to add org.mongodb/mongodb-driver-core/4.11.1 and org.mongodb/bson/4.11.1 to the dependencies. |
@J-N-K @lsiepel Thanks for your efforts, but so far no luck. Like I mentioned earlier, the build works, I did fix the type problems. The only build step which fails is "karaf:verify" - I can even find the created jar file. So this seems to be something I miss in the karaf runtime dependencies, which needs to be added. The resulting feature.xml looks good to me:
You might want to give it a try with the commit and see whether you receive the same build errors. Build command I use: |
Tried your commit and play with it for over an hour, but i fail to see what is wrong. I'm no karaf/feature/dependency expert, so hope someone else has time to look into this. |
Got a bit further, now it fails in openhab ;-)
Used this feature.xml
Next step - learning how to either load the driver during runtime or include it in the jar file... |
You don't need to add anything to the feature.xml. Just add all dependencies to the pom.xml with scope |
@J-N-K Thanks for the hint - so far this did not change anything. Got a bit further - now it complains about missing com.amazonaws.auth - and when I drill further even more missing things pop up. So I make progress and will continue later on... |
In case of |
@J-N-K Thanks for the hints - it took me some time to get all dependencies right and it finally works with MongoDB 6.0 ;-) Before creating the pull request - I will fix the bug here and add some unittests as well. |
…helper, fixing type handling for HSBType, RawType and QuantityType
…some tests if docker is missing.
Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
…it tests Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
…helper, fixing type handling for HSBType, RawType and QuantityType Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
…some tests if docker is missing. Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
…some tests if docker is missing. Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
… the data where possible
Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
…it tests Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
…helper, fixing type handling for HSBType, RawType and QuantityType Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
…some tests if docker is missing. Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
… the data where possible Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
…toString Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
…some tests if docker is missing. Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
… the data where possible Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
…toString Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
…e to be more robust and implemented the ModifiablePersistenceService Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
This issue has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/mongo-db-cannot-be-cast-to-class-java-lang-number/153019/2 |
…e handling (#16333) * #16308 #16310 Upgraded MongoDB driver, added initial unit tests * #16308 #16310 Refactored the MongoDBPersistence adding helper, fixing type handling for HSBType, RawType and QuantityType * #16308 Added backwardcompatibility for the old way of writting the data where possible * #16308 Added test for larger ImageItems and the limit of 16 MB Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
Pr is merged |
…e handling (openhab#16333) * openhab#16308 openhab#16310 Upgraded MongoDB driver, added initial unit tests * openhab#16308 openhab#16310 Refactored the MongoDBPersistence adding helper, fixing type handling for HSBType, RawType and QuantityType * openhab#16308 Added backwardcompatibility for the old way of writting the data where possible * openhab#16308 Added test for larger ImageItems and the limit of 16 MB Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com> Signed-off-by: Jørgen Austvik <jaustvik@acm.org>
Expected Behavior
If I query the historic states in analyze, graphing or use the persistence interface, I want to get the stored states and no error ;-)
Current Behavior
In Openhab I query the history for an item and want to get the stored states for a given timerange.
In the MainUI - I navigate to the settings->items and select an item with a type of Number:Energy and want analyze it's value, but nothing gets returned, but in the log I see:
Possible Solution
I checked the code for the MongoDB persistence service and see that in https://github.com/openhab/openhab-addons/blob/9e1f87db86409ec2ea1a36ea0de64bbd14c79608/bundles/org.openhab.persistence.mongodb/src/main/java/org/openhab/persistence/mongodb/internal/MongoDBPersistenceService.java
Method public Iterable query(FilterCriteria filter) {
Does not deal with quantity types as well as the write operation does not - it uses a private Object convertValue(State state) { with
Both will handle Quantity Types as "String", but for sure all other components do expect a QuantityType like it is done in the influxdb persistence service:
I'm unsure, whether to fix this in the read or write section of the mongodb persistence service
Steps to Reproduce (for Bugs)
Create a Number:Energy typed item, pump values in and try to graph it.
Context
I'm trying to use the mongodb persistence service instead of influxdb.
Your Environment
The text was updated successfully, but these errors were encountered: