You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by narges saleh <sn...@gmail.com> on 2020/01/18 12:28:34 UTC

CacheKeyConfiguration

Hi All,

I understand that CacheKeyConfiguration is defined at ignite configuration
level. That being the case, how do you tie the affinity key to a particular
cache, within the XML config file?
The following code snippet shows how to do in java code.

  CacheConfiguration<PersonKey, Person> personCfg = new
CacheConfiguration<PersonKey, Person>("persons");

    //configure the affinity key
    personCfg.setKeyConfiguration(new CacheKeyConfiguration("Person",
"companyId"));

Also, how do you define an affinity key with multiple fields, using
CacheKeyConfiguration, say SSN and company id are both part of the
affinity key.

thanks.

Re: CacheKeyConfiguration

Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!

I don't think we support multiple affinity fields yet.

You will need to create a synthetic field, which you will keep populated
with all affinity columns' values, and declare it as affinity field.

Regards,
-- 
Ilya Kasnacheev


сб, 18 янв. 2020 г. в 15:28, narges saleh <sn...@gmail.com>:

> Hi All,
>
> I understand that CacheKeyConfiguration is defined at ignite configuration
> level. That being the case, how do you tie the affinity key to a particular
> cache, within the XML config file?
> The following code snippet shows how to do in java code.
>
>   CacheConfiguration<PersonKey, Person> personCfg = new CacheConfiguration<PersonKey, Person>("persons");
>
>     //configure the affinity key
>     personCfg.setKeyConfiguration(new CacheKeyConfiguration("Person", "companyId"));
>
> Also, how do you define an affinity key with multiple fields, using CacheKeyConfiguration, say SSN and company id are both part of the affinity key.
>
> thanks.
>
>

Re: CacheKeyConfiguration

Posted by narges saleh <sn...@gmail.com>.
Hello Stephan,
I understand, but the tables with large volume of data would have these two
keys in them. I can replicate the smaller tables. I suppose I will need to
generate a surrogate key for these "affinity keys". Still I do not want to
use a POJO if I can help it.

The other question I had was what if I have two sets of tables with two
different affinity keys, some on key A and some other on key B. Do I need
to put these in separate ignite clusters?

thanks.

On Tue, Jan 21, 2020 at 5:48 AM Ilya Kasnacheev <il...@gmail.com>
wrote:

> Hello!
>
> Even if you had two affinity keys, you would not be able to do collocated
> joins with tables employing different affinity keys.
>
> I.e., if you had a table with affinity key (city_id, country_id) you will
> only be able to collocate it with another table of affinity key (city_id,
> country_id), but NOT with tables using affinity keys (city_id),
> (country_id) or (country_id, city_id).
>
> You will have to think around this limitation by choosing the most
> important criteria to collocate data on, and doing the rest via lookup
> tables or distributed joins.
>
> Regards,
> --
> Ilya Kasnacheev
>
>
> пн, 20 янв. 2020 г. в 21:48, narges saleh <sn...@gmail.com>:
>
>> Thanks Stephan,
>>
>> I don't want to use POJO classes if I can help it.
>> I want to mimic the following in my configuration file:
>>
>> CREATE TABLE IF NOT EXISTS Person (
>>   id int,
>>   city_id int,
>>   name varchar,
>>   age int,
>>   company varchar,
>>   PRIMARY KEY (id, city_id)) WITH "template=partitioned,affinity_key=city_id";
>>
>> Furthermore, I want to see if it is possible to define affinity over multiple keys, for example, have the above as
>>
>> CREATE TABLE IF NOT EXISTS Person (
>>   id int,
>>   city_id int,
>>   name varchar,
>>   age int,
>>   company varchar,
>>   PRIMARY KEY (id, city_id)) WITH "template=partitioned,*affinity_key=city_id, country_id"*
>>
>> *;*
>>
>> I have many caches and the relationship between them imply different set of affinity keys. All are defined within the same configuration file.
>>
>>
>> On Mon, Jan 20, 2020 at 12:40 PM narges saleh <sn...@gmail.com>
>> wrote:
>>
>>> Thanks Stephan,
>>>
>>> I don't want to use POJO classes if I can help it.
>>> I want to mimic the following in my configuration file:
>>>
>>>
>>> On Mon, Jan 20, 2020 at 10:30 AM Stephen Darlington <
>>> stephen.darlington@gridgain.com> wrote:
>>>
>>>> Details on how to configure affinity colocation can be found in the
>>>> documentation:
>>>> https://www.gridgain.com/docs/latest/developers-guide/data-modeling/affinity-collocation
>>>>
>>>>
>>>> In short, use the “indexedTypes” property in the XML file and the
>>>> @AffinityKeyMapped annotation in your POJO key,
>>>>
>>>> Regards,
>>>> Stephen
>>>>
>>>> On 18 Jan 2020, at 12:28, narges saleh <sn...@gmail.com> wrote:
>>>>
>>>> Hi All,
>>>>
>>>> I understand that CacheKeyConfiguration is defined at ignite
>>>> configuration level. That being the case, how do you tie the affinity key
>>>> to a particular cache, within the XML config file?
>>>> The following code snippet shows how to do in java code.
>>>>
>>>>   CacheConfiguration<PersonKey, Person> personCfg = new CacheConfiguration<PersonKey, Person>("persons");
>>>>
>>>>     //configure the affinity key
>>>>     personCfg.setKeyConfiguration(new CacheKeyConfiguration("Person", "companyId"));
>>>>
>>>> Also, how do you define an affinity key with multiple fields, using CacheKeyConfiguration, say SSN and company id are both part of the affinity key.
>>>>
>>>> thanks.
>>>>
>>>>
>>>>
>>>>

Re: CacheKeyConfiguration

Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!

Even if you had two affinity keys, you would not be able to do collocated
joins with tables employing different affinity keys.

I.e., if you had a table with affinity key (city_id, country_id) you will
only be able to collocate it with another table of affinity key (city_id,
country_id), but NOT with tables using affinity keys (city_id),
(country_id) or (country_id, city_id).

You will have to think around this limitation by choosing the most
important criteria to collocate data on, and doing the rest via lookup
tables or distributed joins.

Regards,
-- 
Ilya Kasnacheev


пн, 20 янв. 2020 г. в 21:48, narges saleh <sn...@gmail.com>:

> Thanks Stephan,
>
> I don't want to use POJO classes if I can help it.
> I want to mimic the following in my configuration file:
>
> CREATE TABLE IF NOT EXISTS Person (
>   id int,
>   city_id int,
>   name varchar,
>   age int,
>   company varchar,
>   PRIMARY KEY (id, city_id)) WITH "template=partitioned,affinity_key=city_id";
>
> Furthermore, I want to see if it is possible to define affinity over multiple keys, for example, have the above as
>
> CREATE TABLE IF NOT EXISTS Person (
>   id int,
>   city_id int,
>   name varchar,
>   age int,
>   company varchar,
>   PRIMARY KEY (id, city_id)) WITH "template=partitioned,*affinity_key=city_id, country_id"*
>
> *;*
>
> I have many caches and the relationship between them imply different set of affinity keys. All are defined within the same configuration file.
>
>
> On Mon, Jan 20, 2020 at 12:40 PM narges saleh <sn...@gmail.com>
> wrote:
>
>> Thanks Stephan,
>>
>> I don't want to use POJO classes if I can help it.
>> I want to mimic the following in my configuration file:
>>
>>
>> On Mon, Jan 20, 2020 at 10:30 AM Stephen Darlington <
>> stephen.darlington@gridgain.com> wrote:
>>
>>> Details on how to configure affinity colocation can be found in the
>>> documentation:
>>> https://www.gridgain.com/docs/latest/developers-guide/data-modeling/affinity-collocation
>>>
>>>
>>> In short, use the “indexedTypes” property in the XML file and the
>>> @AffinityKeyMapped annotation in your POJO key,
>>>
>>> Regards,
>>> Stephen
>>>
>>> On 18 Jan 2020, at 12:28, narges saleh <sn...@gmail.com> wrote:
>>>
>>> Hi All,
>>>
>>> I understand that CacheKeyConfiguration is defined at ignite
>>> configuration level. That being the case, how do you tie the affinity key
>>> to a particular cache, within the XML config file?
>>> The following code snippet shows how to do in java code.
>>>
>>>   CacheConfiguration<PersonKey, Person> personCfg = new CacheConfiguration<PersonKey, Person>("persons");
>>>
>>>     //configure the affinity key
>>>     personCfg.setKeyConfiguration(new CacheKeyConfiguration("Person", "companyId"));
>>>
>>> Also, how do you define an affinity key with multiple fields, using CacheKeyConfiguration, say SSN and company id are both part of the affinity key.
>>>
>>> thanks.
>>>
>>>
>>>
>>>

Re: CacheKeyConfiguration

Posted by narges saleh <sn...@gmail.com>.
Thanks Stephan,

I don't want to use POJO classes if I can help it.
I want to mimic the following in my configuration file:

CREATE TABLE IF NOT EXISTS Person (
  id int,
  city_id int,
  name varchar,
  age int,
  company varchar,
  PRIMARY KEY (id, city_id)) WITH "template=partitioned,affinity_key=city_id";

Furthermore, I want to see if it is possible to define affinity over
multiple keys, for example, have the above as

CREATE TABLE IF NOT EXISTS Person (
  id int,
  city_id int,
  name varchar,
  age int,
  company varchar,
  PRIMARY KEY (id, city_id)) WITH
"template=partitioned,*affinity_key=city_id, country_id"*

*;*

I have many caches and the relationship between them imply different
set of affinity keys. All are defined within the same configuration
file.


On Mon, Jan 20, 2020 at 12:40 PM narges saleh <sn...@gmail.com> wrote:

> Thanks Stephan,
>
> I don't want to use POJO classes if I can help it.
> I want to mimic the following in my configuration file:
>
>
> On Mon, Jan 20, 2020 at 10:30 AM Stephen Darlington <
> stephen.darlington@gridgain.com> wrote:
>
>> Details on how to configure affinity colocation can be found in the
>> documentation:
>> https://www.gridgain.com/docs/latest/developers-guide/data-modeling/affinity-collocation
>>
>>
>> In short, use the “indexedTypes” property in the XML file and the
>> @AffinityKeyMapped annotation in your POJO key,
>>
>> Regards,
>> Stephen
>>
>> On 18 Jan 2020, at 12:28, narges saleh <sn...@gmail.com> wrote:
>>
>> Hi All,
>>
>> I understand that CacheKeyConfiguration is defined at ignite
>> configuration level. That being the case, how do you tie the affinity key
>> to a particular cache, within the XML config file?
>> The following code snippet shows how to do in java code.
>>
>>   CacheConfiguration<PersonKey, Person> personCfg = new CacheConfiguration<PersonKey, Person>("persons");
>>
>>     //configure the affinity key
>>     personCfg.setKeyConfiguration(new CacheKeyConfiguration("Person", "companyId"));
>>
>> Also, how do you define an affinity key with multiple fields, using CacheKeyConfiguration, say SSN and company id are both part of the affinity key.
>>
>> thanks.
>>
>>
>>
>>

Re: CacheKeyConfiguration

Posted by narges saleh <sn...@gmail.com>.
Thanks Stephan,

I don't want to use POJO classes if I can help it.
I want to mimic the following in my configuration file:


On Mon, Jan 20, 2020 at 10:30 AM Stephen Darlington <
stephen.darlington@gridgain.com> wrote:

> Details on how to configure affinity colocation can be found in the
> documentation:
> https://www.gridgain.com/docs/latest/developers-guide/data-modeling/affinity-collocation
>
>
> In short, use the “indexedTypes” property in the XML file and the
> @AffinityKeyMapped annotation in your POJO key,
>
> Regards,
> Stephen
>
> On 18 Jan 2020, at 12:28, narges saleh <sn...@gmail.com> wrote:
>
> Hi All,
>
> I understand that CacheKeyConfiguration is defined at ignite configuration
> level. That being the case, how do you tie the affinity key to a particular
> cache, within the XML config file?
> The following code snippet shows how to do in java code.
>
>   CacheConfiguration<PersonKey, Person> personCfg = new CacheConfiguration<PersonKey, Person>("persons");
>
>     //configure the affinity key
>     personCfg.setKeyConfiguration(new CacheKeyConfiguration("Person", "companyId"));
>
> Also, how do you define an affinity key with multiple fields, using CacheKeyConfiguration, say SSN and company id are both part of the affinity key.
>
> thanks.
>
>
>
>

Re: CacheKeyConfiguration

Posted by Stephen Darlington <st...@gridgain.com>.
Details on how to configure affinity colocation can be found in the documentation: https://www.gridgain.com/docs/latest/developers-guide/data-modeling/affinity-collocation 

In short, use the “indexedTypes” property in the XML file and the @AffinityKeyMapped annotation in your POJO key,

Regards,
Stephen

> On 18 Jan 2020, at 12:28, narges saleh <sn...@gmail.com> wrote:
> 
> Hi All,
> 
> I understand that CacheKeyConfiguration is defined at ignite configuration level. That being the case, how do you tie the affinity key to a particular cache, within the XML config file?
> The following code snippet shows how to do in java code.
>   CacheConfiguration<PersonKey, Person> personCfg = new CacheConfiguration<PersonKey, Person>("persons");
>    
>     //configure the affinity key
>     personCfg.setKeyConfiguration(new CacheKeyConfiguration("Person", "companyId"));
> 
> Also, how do you define an affinity key with multiple fields, using CacheKeyConfiguration, say SSN and company id are both part of the affinity key.
> thanks.