Skip to content

WiP: @Unique and @Index (Any help is welcome) #120

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

Closed
wants to merge 12 commits into from

Conversation

Buggaboo
Copy link
Contributor

@Buggaboo Buggaboo commented Sep 26, 2020

I have a basic implementation, but the tests keep exploding with this though:

ObjectBoxException: failed to create store: 10501 No index ID/UID assigned for indexed property: Property uByte (15, Byte)

This error applies to all the @Unique annotated fields.

Afaik objectbox-model.json seems normal.

Help!

…roperty)

The tests keep exploding with this though:

ObjectBoxException: failed to create store: 10501 No index ID/UID assigned for indexed property: Property uByte (15, Byte)

Even objectbox-model.json seems normal.
@Buggaboo Buggaboo changed the title Don't merge! Help needed for implementation of @Unique Don't merge! Help needed for @Unique Sep 26, 2020
@greenrobot-team
Copy link
Member

greenrobot-team commented Sep 28, 2020

Just some quick feedback: @Unique is actually just a special @Index. So this AFAIK won't work without adding support for indexes first (at least that's how it works in Java). An index needs to get assigned an id/uid and be stored in the model file.

@greenrobot-team
Copy link
Member

None of our examples use an index, yet. I should change that. ^^

OK, more details: the model file needs an indexId for each property. The last index id ever used should also be set as lastIndexId. Retired index UIDs need to move to retiredIndexUids.

...
        {
          "id": "13:8914743272487704330",
          "name": "dateProp",
          "indexId": "12:1548007883894887437",
          "type": 10,
          "flags": 8
        }
...
  "lastIndexId": "12:1548007883894887437",
...
  "retiredIndexUids": [],

So this is actually a lot more work than just adding the UNIQUE or INDEXED flag.

@Buggaboo
Copy link
Contributor Author

What's the difference between id and uid?

@greenrobot-team
Copy link
Member

What's the difference between id and uid?

IDs are given out in order (1, 2, 3...). The UID is a random number that identifies something over the lifetime of the Store.
https://docs.objectbox.io/advanced/meta-model-ids-and-uids goes into more details on this.

Side note: I updated the Kotlin example to use an index.
https://github.com/objectbox/objectbox-examples/tree/main/android-app-kotlin

…ing apart

@unique and @Index are sharing the same logic.
After turning them off this popped beautiful gem up:
ObjectBoxException: failed to create store: 10001 State condition failed in assignIdsForProperty:476: indexId <= catalog.lastIndexId()
@Buggaboo
Copy link
Contributor Author

Buggaboo commented Sep 29, 2020

It took some work, but there should be a unified way to setup the models.

ObjectBoxException: failed to create store: 10001 State condition failed in assignIdsForProperty:476: indexId <= catalog.lastIndexId()

I have no idea what the above means, but its breaking everything.
I did stupid stuff like indexing booleans etc. only I got an OBException in runtime about the indexed float types.

Which other types are considered not a good idea to index/unique?

Help!

@greenrobot-team
Copy link
Member

Thanks!

It's odd that objectbox.h does not document types that do not support an index. Peeking at the Java docs: https://docs.objectbox.io/entity-annotations#property-indexes-with-index Java byte arrays, float and double can't be indexed.

@greenrobot-team
Copy link
Member

Thanks for getting this started! If time permits it I might continue on this tomorrow. It's kind of hard to get this right without any docs on how this should work internally.

@Buggaboo Buggaboo changed the title Don't merge! Help needed for @Unique WiP: @Unique and @Index (Any help is welcome) Oct 5, 2020
@vaind
Copy link
Contributor

vaind commented Nov 28, 2020

replaced by #123

@vaind vaind closed this Nov 28, 2020
@Buggaboo Buggaboo deleted the feature/annotation-candy branch November 30, 2020 15:13
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

Successfully merging this pull request may close these issues.

3 participants