You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by vkulichenko <va...@gmail.com> on 2016/08/15 18:05:29 UTC

Re: Data collocation question

Hi,

Please properly subscribe to the mailing list so that the community can
receive email notifications for your messages. To subscribe, send empty
email to user-subscribe@ignite.apache.org and follow simple instructions in
the reply.


AdamDec wrote
> Hi,
> I have a simple 1:N relation (1 Client can have multiple page views)
> 
> I would like to collocate data using clientId so that all the pageviews
> for given client resides on the same node (data locality)
*
> Classes:
*
> 
> public class ClientData implements Serializable {
> 
>     @QuerySqlField(index = true)
>     @JsonProperty("customClientId")
>     public long customClientId;
> 
>     @QuerySqlField(index = true)
>     @JsonProperty("clientParams")
>     public ClientParams clientParams;
> }
> 
> public class ClientParams implements Serializable {
> 
>     @QuerySqlField(index = true)
>     @JsonProperty("email")
>     public String email;
> 
>     @QuerySqlField(index = true)
>     @JsonProperty("saldo")
>     public long saldo;
> 
> 
> public class PageVisit implements Serializable {
> 
>     @QuerySqlField(index = true)
>     @JsonProperty("id")
>     public long id;
> 
>     @QuerySqlField(index = true)
>     @JsonProperty("customClientId")
>     public long customClientId;
> 
>     @QuerySqlField(index = true)
>     @JsonProperty("pageParams")
>     public PageParams pageParams;
> }
> 
> public class PageParams implements Serializable {
> 
>     @QuerySqlField(index = true)
>     @JsonProperty("ref")
>     public String ref;
> }
*
> Cache setup:
*
> 
> final CacheConfiguration&lt;Long, ClientData&gt; clientsCacheCfg = new
> CacheConfiguration<>(CLIENTS_CACHE);
> clientsCacheCfg.setIndexedTypes(Long.class, ClientData.class,
> String.class, ClientData.class);
> final IgniteCache&lt;Long, ClientData&gt; clientsCache =
> ignite.getOrCreateCache(clientsCacheCfg);
> 
> final CacheConfiguration&lt;AffinityKey&lt;Long&gt;, PageVisit>
> pageVisitCacheCfg = new CacheConfiguration<>(PAGE_VISIT_CACHE);
> pageVisitCacheCfg.setIndexedTypes(AffinityKey.class, PageVisit.class,
> String.class, PageVisit.class, Long.class, PageVisit.class);
> final IgniteCache&lt;AffinityKey&lt;Long&gt;, PageVisit> pageVisitCache =
> ignite.getOrCreateCache(pageVisitCacheCfg);
> 
> To add the data into cache I am using streamers:
> clientsStreamer.addData(CLIENT_ID.get(), client);
> 
> final AffinityKey
> <Long>
>  pageVisitAffinityKey = new AffinityKey<>(PAGE_VISIT_ID.get(),
> CLIENT_ID.get());
> pageVisitStreamer.addData(pageVisitAffinityKey, pageVisit);
*
> Question1: Is it the right way of doing it?
*
> 
*
> Question2: pageVisitCacheCfg.setIndexedTypes -> should I put all the
> datatypes for PageVisit class that I wish to have index on?
*
Everything looks correct, but setIndexedTypes should only define key and
value class pairs. Long->ClientData for the first cache,
AffinityKey->PageVisit for second.

You can also refer to query example [1], which has similar relationship
between Person and Organization.

[1]
https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Data-collocation-question-tp7042p7072.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Data collocation question

Posted by vkulichenko <va...@gmail.com>.
AdamDec wrote
> hmm...but I have several indexes///with different types, what than?

In setIndexedTypes you have to provide classes that are scanned for
annotations. These classes can define multiple indexes.

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Data-collocation-question-tp7042p7108.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.