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

where in throws : Unsupported comparison between type 'uuid' and type 'string'

Open amer-zk opened this issue 3 years ago • 3 comments

Problem

I have UUID as primary key in my class

I want to make this query:

UUID[] values = new UUID[]{ UUID.fromString(key1) }; query.in("uuid_field" , values);

exception will thrown : Unsupported comparison between type 'uuid' and type 'string'

how can i acheive that ?

JAVA - android studio , realm DB

Solution

No response

Alternatives

No response

How important is this improvement for you?

I'd like to see it, but have a workaround

amer-zk avatar Jul 29 '22 19:07 amer-zk

Hi @amer-zk. There is currently no way to use in with non-primitive types, so you would have to build the query manually with something like

RealmQuery<...> query = realm.where(....).beginGroup();
Boolean first = true;
for (UUID uuid : uuids) {
    if (first) {
        first = false;
    } else {
        query.or();
    }
    query.equalTo("uuid_field", uuid);
}
query.endGroup();

rorbech avatar Aug 10 '22 07:08 rorbech

Hi @amer-zk. There is currently no way to use in with non-primitive types, so you would have to build the query manually with something like

RealmQuery<...> query = realm.where(....).beginGroup();
Boolean first = true;
for (UUID uuid : uuids) {
    if (first) {
        first = false;
    } else {
        query.or();
    }
    query.equalTo("uuid_field", uuid);
}
query.endGroup();

i think thats will lead to performance issue ! it must be optimized to excute without loops!

amer-zk avatar Aug 10 '22 17:08 amer-zk

We just recently added support for querying with multiple values in the underlying core implementation but haven't adopted this in the SDK yet. We are currently focusing on getting features into the Realm Kotlin SDK so you can track the adoption of this in https://github.com/realm/realm-kotlin/issues/929. To fully cover your use case we would also need support for type coercion as part of the query engine. That will most probably be handled as part of https://github.com/realm/realm-kotlin/issues/587.

rorbech avatar Aug 29 '22 10:08 rorbech