objectbox / objectbox/objectbox-java
QueryBuilder's notEqual doesn't return objects where that field is null
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.6k
- Forks
- 311
- PR merge metrics
- No merged PRs in 30d
Description
It's in the title, but a concrete example would be. Say we have a model with a String field called field. We have two objects in the database, one of them has field set to an empty String and another one has it set to null. The following query returns the one with the empty field but not the one with null:
box.query().notEqual(Model_.field, "hello world").build().find()
Basic info (please complete the following information):
- ObjectBox version: latest (2.7.1)
- Reproducibility: always
- Device: any
- OS: any
Expected behavior
An object with a particular field being null should match a notEqual which contains any non-null value, instead it doesn't.
Code
store = MyObjectBox.builder().androidContext(this).buildDefault()
val box = store.boxFor(Model::class.java)
box.removeAll()
Log.d("TEST_LOG", "putting null with id: " + box.put(Model(0, null)))
Log.d("TEST_LOG", "putting empty with id: " + box.put(Model(0, "")))
val logString = models.map { it.id }.sorted().joinToString()
Log.d("TEST_LOG", "models: $logString")
Where Model has a single String field called field
The above code clearly logs only the model with the empty field being returned but not the one with the null value for field. Maybe I'm misunderstanding something but this is a very unintuitive definition of notEqual and nothing in the docs seems to indicate it would behave this way.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at QueryBuilder.notEqual and follow the query path used by box.query().notEqual(Model_.field, "hello world").build().find(), focusing on how null field values are handled. Add a regression case based on the Model examples and verify that the query returns both the empty-string and null objects.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100