IMap vs MultiMap

851 views
Skip to first unread message

Neil Martin

unread,
Jul 6, 2012, 11:02:25 PM7/6/12
to haze...@googlegroups.com
If I have an IMap that's typed as follows - IMap<K, Set<V>>, can I still use a predicate that references the keys?  Assuming the key is "id", would I be able to do something like this as a predicate :  "id IN (1,2,3,4,5)"?  Thus enabling me to look up the values for multiple keys in a single operation.

I know I can use a MultiMap to store multiple values at a key, but one get can only lookup the values for a single key at a time.


Enes Akar

unread,
Jul 9, 2012, 3:33:13 AM7/9/12
to haze...@googlegroups.com
You can use predicate builder as follows:

        HazelcastInstance instance = Hazelcast.newHazelcastInstance(null);
        IMap<String, String> map = instance.getMap("map");
        map.put("key1", "value1");
        map.put("key2", "value2");
        EntryObject e = new PredicateBuilder().getEntryObject();
        Predicate p1 = e.key().equal("key1");
        Predicate predicate = e.key().equal("key2").or(p1);
        Collection values = map.values(predicate);
        System.out.println(values.size());

On Sat, Jul 7, 2012 at 6:02 AM, Neil Martin <nsm...@gmail.com> wrote:
If I have an IMap that's typed as follows - IMap<K, Set<V>>, can I still use a predicate that references the keys?  Assuming the key is "id", would I be able to do something like this as a predicate :  "id IN (1,2,3,4,5)"?  Thus enabling me to look up the values for multiple keys in a single operation.

I know I can use a MultiMap to store multiple values at a key, but one get can only lookup the values for a single key at a time.


--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To view this discussion on the web visit https://groups.google.com/d/msg/hazelcast/-/lXe370sdSa4J.
To post to this group, send email to haze...@googlegroups.com.
To unsubscribe from this group, send email to hazelcast+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hazelcast?hl=en.

Neil Martin

unread,
Jul 9, 2012, 10:22:32 PM7/9/12
to haze...@googlegroups.com
Thanks for the reply, although I think I need some clarification.  Should I assume that since you posted an example of a custom predicate, that I can't solve this with a SqlPredicate?  Just want to make sure I'm not missing something...



On Monday, July 9, 2012 2:33:13 AM UTC-5, Enes Akar wrote:
You can use predicate builder as follows:

        HazelcastInstance instance = Hazelcast.newHazelcastInstance(null);
        IMap<String, String> map = instance.getMap("map");
        map.put("key1", "value1");
        map.put("key2", "value2");
        EntryObject e = new PredicateBuilder().getEntryObject();
        Predicate p1 = e.key().equal("key1");
        Predicate predicate = e.key().equal("key2").or(p1);
        Collection values = map.values(predicate);
        System.out.println(values.size());

On Sat, Jul 7, 2012 at 6:02 AM, Neil Martin wrote:
If I have an IMap that's typed as follows - IMap<K, Set<V>>, can I still use a predicate that references the keys?  Assuming the key is "id", would I be able to do something like this as a predicate :  "id IN (1,2,3,4,5)"?  Thus enabling me to look up the values for multiple keys in a single operation.

I know I can use a MultiMap to store multiple values at a key, but one get can only lookup the values for a single key at a time.


--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To view this discussion on the web visit https://groups.google.com/d/msg/hazelcast/-/lXe370sdSa4J.
To post to this group, send email to haze...@googlegroups.com.
To unsubscribe from this group, send email to hazelcast+unsubscribe@googlegroups.com.

Enes Akar

unread,
Jul 10, 2012, 1:42:26 AM7/10/12
to haze...@googlegroups.com
Yes currently it is not possible with sql-predicate.
But for such a feature you may create an enhancement issue on github.

To view this discussion on the web visit https://groups.google.com/d/msg/hazelcast/-/d2rrgV8jpn4J.

To post to this group, send email to haze...@googlegroups.com.
To unsubscribe from this group, send email to hazelcast+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages