Search code examples
javadistributed-computinghazelcast

How to use Distributed Query API like Criteria API or Distributed Sql Query with any data structures other than IMap?


I want to use a distributed query, create predicate and use that predicate to filter data from a list. How can I use the predicate with IList?

I have gone through Hazelcast IMDG 3.12 Documentation but it only shows usage with IMAP. Can someone let me know if distributed queries are only applicable to IMAP or are it applicable to other data structures as well?


Solution

  • An IMap is a collection of objects. An IList is a single object that is a collection.

    Searching for matches is currently only implemented for the former. So, to look for matches you have to do this yourself.

    You can iterate through the list as if it was a standard Java list, but this means retrieving the complete list to the caller. The whole list is copied from where it is held to the caller, possibly inefficient for network transfer if the list is large compared to the required matches.

    You could submit a callable that applies the list iterator on the host with the list, running the filtering without moving the whole list across the network, only returning the matches.

    Also, Jet can treat a list as a source (see here), so if you wanted you could build your own filter that applies to the data where it is located. Probably too much work for adhoc requests, but another option.