objectbox / objectbox/objectbox-java

QueryBuilder's notEqual doesn't return objects where that field is null

Offen
#915 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

enhancement
Vorherrschende Sprache
Java
Sterne
4.6k
Forks
311
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne bei QueryBuilder.notEqual und verfolge den von box.query().notEqual(Model_.field, "hello world").build().find() verwendeten Abfragepfad, wobei du dich darauf konzentrierst, wie null-Feldwerte behandelt werden. Füge einen Regressionstest basierend auf den Model-Beispielen hinzu und verifiziere, dass die Abfrage sowohl das Objekt mit der leeren Zeichenkette als auch das Objekt mit null zurückgibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java, kotlin
Bereich
database
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.