Re: Cache Structure

2018-11-30 Thread Ilya Kasnacheev
Hello!

You can implement Binarylizable which will serialize your objects so that
your relevant k1 and k2 are stored as entries in BinaryObject.
You can then add QueryEntity to cache to be able to index them properly.

Regards,
-- 
Ilya Kasnacheev


чт, 15 нояб. 2018 г. в 01:33, Ramin Farajollah :

> Thanks for your informative reply.
>
> I looked at CacheQueryExample to be able to query by both unique (k1) and
> non-unique (k2) keys.
>
> I use an /AffinityKey/. However, k1 (unique key) and k2
> (non-unique key) are not member variables, where I would have been able to
> annotate them with /@QuerySqlField(index = true)/ (with true and false,
> respectively). They are entries of a map inside of T. There are getter
> methods for both.
>
> Having said that:
>
> 1. How do I identify the k1 to be an index key so I can execute a query
> with
> a predicate like this: "k1 = ?"
> I saw this post:  [Q1]
> <
> http://apache-ignite-users.70518.x6.nabble.com/Querying-HashMap-stored-as-value-in-IgniteCache-td3507.html#a3550>
>
>
> 2. Will the same strategy work for a query based on a non-unique key (k2)
> in
> the same map within T?
>
>
>
> Andrew Mashenkov wrote
> > If k2 <- k1 relation is one-to-many, there is another way to achieve the
> > same with using SQL [2].
> > With this approach adding new instance will be a single operation on one
> > node and Ignite will need just to update local index in addition, but
> > query
> > for k2 will be a broadcast unless the data is collocated [3].
>
>
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>


Re: Cache Structure

2018-11-14 Thread Ramin Farajollah
Thanks for your informative reply.

I looked at CacheQueryExample to be able to query by both unique (k1) and
non-unique (k2) keys.

I use an /AffinityKey/. However, k1 (unique key) and k2
(non-unique key) are not member variables, where I would have been able to
annotate them with /@QuerySqlField(index = true)/ (with true and false,
respectively). They are entries of a map inside of T. There are getter
methods for both.

Having said that:

1. How do I identify the k1 to be an index key so I can execute a query with
a predicate like this: "k1 = ?"
I saw this post:  [Q1]

  

2. Will the same strategy work for a query based on a non-unique key (k2) in
the same map within T?



Andrew Mashenkov wrote
> If k2 <- k1 relation is one-to-many, there is another way to achieve the
> same with using SQL [2].
> With this approach adding new instance will be a single operation on one
> node and Ignite will need just to update local index in addition, but
> query
> for k2 will be a broadcast unless the data is collocated [3].





--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/


Re: Cache Structure

2018-11-13 Thread Andrey Mashenkov
Hi,

Yes, to add a new item to a list value of second cache Ignite will have to
deserialize whole list (with all it's items) then add new item and then
serialize list again.
You can try to use BinaryObjects to avoid unnecessary deserialization of
list items [1].
Also note, k2 and k1 data will have different distribution and adding new
instance of T will requires 2 operations (as you mentioned) on different
nodes.


If k2 <- k1 relation is one-to-many, there is another way to achieve the
same with using SQL [2].
With this approach adding new instance will be a single operation on one
node and Ignite will need just to update local index in addition, but query
for k2 will be a broadcast unless the data is collocated [3].


[1]
https://apacheignite.readme.io/docs/binary-marshaller#section-binaryobject-cache-api
[2]
https://apacheignite-sql.readme.io/docs/java-sql-api#section-sqlfieldsqueries
[3] https://apacheignite.readme.io/docs/affinity-collocation

On Tue, Nov 13, 2018 at 11:34 PM Ramin Farajollah (BLOOMBERG/ 731 LEX) <
rfarajol...@bloomberg.net> wrote:

> Hi,
>
> Please help me structure the cache to store instances of a type, say T.
> I'd like to cache the objects in two different ways:
>
> 1. By a unique key (k1), where the value is a single instance
> 2. By a non-unique key (k2), where the value is a list of instances
>
> Please comment on my approach:
>
> - Create a cache with k1 to an instance of T.
> - Create a second cache with k2 to a list of k1 keys.
> - To add a new instance of T, I will have to update both caches. Will this
> result in serializing the instance (in the first cache) and the list of
> keys (in the send cache)? -- Assume not on-heap.
> - If so, will each addition/deletion re-serialize the entire list in the
> second cache?
>
> Thank you!
> Ramin
>
>

-- 
Best regards,
Andrey V. Mashenkov


Cache Structure

2018-11-13 Thread Ramin Farajollah (BLOOMBERG/ 731 LEX)
Hi,

Please help me structure the cache to store instances of a type, say T.
I'd like to cache the objects in two different ways:

1. By a unique key (k1), where the value is a single instance
2. By a non-unique key (k2), where the value is a list of instances

Please comment on my approach:

- Create a cache with k1 to an instance of T.
- Create a second cache with k2 to a list of k1 keys.
- To add a new instance of T, I will have to update both caches. Will this 
result in serializing the instance (in the first cache) and the list of keys 
(in the send cache)? -- Assume not on-heap.
- If so, will each addition/deletion re-serialize the entire list in the second 
cache?

Thank you!
Ramin