Realm-cocoa: Unsupported predicates

Created on 11 Feb 2015  Â·  38Comments  Â·  Source: realm/realm-cocoa

  • [ ] ALL
  • [x] NONE
  • [x] All key path collection queries (@avg, @count, @min, @max, @sum)
  • [x] SUBQUERY
  • [x] LIKE (wildcards * and ? in string searches)
  • [ ] MATCHES
  • [x] diacritic insensitive modifier ([d])
  • [ ] array operations ([index], [SIZE], [FIRST], [LAST])
  • [ ] bitwise (intCol & 1) > 0
  • [ ] SELF
  • [x] multi-level object equality link queries (object.object.object = %@)
  • [x] multi-level object equality link queries with NULL (object.object.object = NULL)
  • [x] %@ IN collection
  • [ ] inequalities on string properties (e.g., stringCol > "some string")
Blocked Pipeline-Idea-Backlog T-Enhancement

Most helpful comment

+1 for diacritic insensitive search

All 38 comments

do you plan to add support for SUBQUERY?

Yes, the goal is to support as much of what NSPredicate allows as possible, but we can't provide a timeline for these just yet.

Dear Realm Team,
Could you add 1more for [d] diacritic insensitive?
I have issue like this and I have to add more property and that's not a compact way.
http://stackoverflow.com/questions/33760078/nsdiacriticinsensitivepredicateoption-not-supported-by-realm
Thanks!

I don't know if someone silently edited the comment in the two hours since you posted this, but there's an entry for "diacritic insensitive modifier ([d])".

Diacritic insensitive modifier will be strongly helped for me as well ;)

SUBQUERY is being added by #2998.

Now a little bit confused, "multi-level object equality link queries" is marked as check, but iam getting

*** Terminating app due to uncaught exception 'Unsupported operator', reason: 'Multi-level object equality link queries are not supported.'

with

RLMResults * result = [UserSubscription objectsWithPredicate:[NSPredicate predicateWithFormat:@"(user = %@) OR (ANY sharings.user = %@)", currentUser, currentUser]];

It looks like that was checked mistakenly. As you note, such queries are not yet supported.

Now that subqueries are implemented ALL should be easy to implement.

Yes, ALL can now be implemented at the binding layer by generating a query equivalent to SUBQUERY(collection, …, …).@count == collection.@count for ALL collection.….

I thought SUBQUERY(collection, …, …).@count == collection.@count was unsupported at the moment because subqueries can only compare @count against a constant value?

That's a limitation of our translation of NSPredicates into core queries, not of core queries.

Gotcha!

%@ IN collection is the same as ANY collection = %@ and does not require new core support.

%@ IN collection is the same as ANY collection = %@ and does not require new core support.

Does it need special support in the binding, or does it already work?

The binding needs to be taught how to recognize that pattern and generate the appropriate core query.

%@ IN collection is being added via #3219.

+1 for diacritic insensitive search

Support for multi-level object equality queries was added in v0.100 as part of #3419.

Do you plan to add support for diacritic insensitive modifier?

Do you plan to add support for diacritic insensitive modifier?

Yes, we're tracking that here.

How is it going with implementing diacritic insensitive? :)

I am curious as well. Apps with foreign language text are difficult to make without diacritic insensitive.

+1 for diacritic insensitive modifier from me as well :)

+1 for diacritic insensitive search and query

+1 for diacritic insensitive search

+1 for multi-level object equality link queries with NULL

Comment for upvotes about bitwise support)

LIKE support was added in #4410.

+1 for diacritic insensitive search

Diacritic-insensitive comparisons are being added in #4742.

Multi-level object equality link queries with NULL are being added in #4743.

@bdash do you know if Realm will support Diacritic-insensitive AND LIKE in the same Predicate? after #4742.

@ppaulojr, diacritic-insensitive LIKE is not currently supported. We intend to support it in the future, but I don't have a timeframe to offer at this time.

+1 for ALL. Any suggestions for a workaround to accomplish the same thing?

I'm reducing an entries realm result set by querying its child objects like this:

entries = entries.filter("ANY aircraft.fieldValues.name = 'Turbine'")
entries = entries.filter("ANY aircraft.fieldValues.bool = true")

But in the end, I get results named Turbine and non-Turbine results that are true. As I understand it, the ALL operator would exclude non-Turbine results and exclude non-true ones.

Any ideas?

@cliftonlabrum, assuming that your intent is to find any aircraft that have a field named turbine with a value of true, you need a subquery rather than ALL. The ALL modifier requires that all members of the collection (fieldValues, in this case) match the criteria before the root object (the member of entries, in this case) is considered a match. Since you likely have multiple fields with different names and values, that isn't what you want. Instead, you want is to ensure that both the name and bool criteria value are evaluated on the same fieldValues object. That's what SUBQUERY is for:

SUBQUERY(aircraft.fieldValues, $fieldValue, $fieldValue.name = 'Turbine' AND $fieldValue.bool = true).@count > 0

You can read the subquery as iterating over aircraft.fieldValues, binding each object to $fieldValue, then evaluating the condition $fieldValue.name = 'Turbine' AND $fieldValue.bool = true on each in turn. We then count how many of the items in fieldValues matched that condition, and consider this entry to match if at least one did.

@bdash Wow, that's really clever. I never even considered using a SUBQUERY. It works great. You're a genius! 🥇

Thank you and have a great weekend!

Is this still active? I'm trying to filter on swift Realm with NSPredicate(format: "ANY tags CONTAINS[cd] %@", rbTag) but a keep getting crashes. How do you filter from a list of strings? My object has a tags property as List<String>

Was this page helpful?
0 / 5 - 0 ratings