Meaning of multiple index types

classic Classic list List threaded Threaded
2 messages Options
colinc colinc
Reply | Threaded
Open this post in threaded view
|

Meaning of multiple index types

When configuring a cache for use with SqlFieldsQuery, it is necessary to call setIndexedTypes(). The below example from the documentation defines 3 types to index:

ccfg.setIndexedTypes(
  MyKey.class, MyValue.class,
  Long.class, MyOtherValue.class,
  UUID.class, String.class
);

If an individual cache can only be used to store objects of one type e.g. MyValue, then what is the meaning of specifying 3 pairs of types in this case? It seems possible to write a query for any of the indexed types but it is only possible to put one type of object in the cache - so querying the other types returns nothing.

I'm interested in this in case it allows me to index and query across a graph of objects. For example if the MyValue class has a collection of MyOtherValue objects, then would it be possible to index and query both objects in the same cache? Or is it only ever possible to query main cache type?

Thanks,
Colin.
Denis Magda Denis Magda
Reply | Threaded
Open this post in threaded view
|

Re: Meaning of multiple index types

Hi Colin,

Please properly subscribe to the user list (this way we will not have to manually approve your emails). All you need to do is send an email to ì user-subscribe@ignite.apache.orgî and follow simple instructions in the reply.

It's possible to store object of different types in the same cache like it's possible to do the same in plain Hashtables and HashMap unless you enable generics that enforce compile time type validation. However there are rare cases when this is useful in practice.

In your case I would suggest you having three different caches collocating data [1] if needed and use distributed SQL query with joins [2] to get aggregated results.

[1] https://apacheignite.readme.io/docs/affinity-collocation
[2] https://apacheignite.readme.io/docs/sql-queries#cross-cache-queries

--
Denis

--------------------------

When configuring a cache for use with SqlFieldsQuery, it is necessary to call setIndexedTypes(). The below example from the documentation defines 3 types to index:

ccfg.setIndexedTypes(
  MyKey.class, MyValue.class,
  Long.class, MyOtherValue.class,
  UUID.class, String.class
);

If an individual cache can only be used to store objects of one type e.g. MyValue, then what is the meaning of specifying 3 pairs of types in this case? It seems possible to write a query for any of the indexed types but it is only possible to put one type of object in the cache - so querying the other types returns nothing.

I'm interested in this in case it allows me to index and query across a graph of objects. For example if the MyValue class has a collection of MyOtherValue objects, then would it be possible to index and query both objects in the same cache? Or is it only ever possible to query main cache type?

Thanks,
Colin.