realm / realm-core

Core database component for the Realm Mobile Database SDKs
https://realm.io
Apache License 2.0
1.02k stars 165 forks source link

Gather queries #982

Open astigsen opened 9 years ago

astigsen commented 9 years ago

Right now all queries return objects from the root of the query (i.e. even if you are querying down through links, you are only able to use it to filter the set you started with). With a gather operator, you would be able to collect objects at bottom of the query instead.

An example would be if you wanted to get a list of all dogs owned by friends of yours:

auto friends_dogs = (people->column<bool>(is_friend) == true).gather(people->column<LinkList>(dogs))

This kind of operator is often needed for graph queries.

cmelchior commented 8 years ago

I just added a a similar issue to Java: https://github.com/realm/realm-java/issues/2232 It sprang up after a discussion on how to document link queries and would be an extremely powerful tool to do some advanced queries.

I think the term often used in functional programming is collect

cmelchior commented 7 years ago

An example of a query that cannot be expressed using any of our current capabilities: https://stackoverflow.com/questions/45529557/realm-querying-with-two-conditions-at-the-same-time/45659934#45659934

bdash commented 7 years ago

@cmelchior, doesn't that simply require a subquery, which is already supported by Core? It can be expressed in Cocoa using a predicate like SUBQUERY(birds, $bird, $bird.type = 2 AND $bird.species.value = 3).@count > 0. That forces both the type and species value portions of the query to be evaluated on the same bird, which looks to be what the user is asking for.

cmelchior commented 7 years ago

Good point. I forgot about subqueries and aggregates, mostly because Java doesn't support them yet.