use of org.apache.ignite.internal.binary.AffinityKey in project ignite by apache.
the class IgniteCacheGroupsSqlTest method joinQuery.
/**
* @param grp1 First cache group.
* @param grp2 Second cache group.
* @param cm1 First cache mode.
* @param cm2 Second cache mode.
* @param cam1 First cache atomicity mode.
* @param cam2 Second cache atomicity mode.
* @throws Exception If failed.
*/
private void joinQuery(String grp1, String grp2, CacheMode cm1, CacheMode cm2, CacheAtomicityMode cam1, CacheAtomicityMode cam2) throws Exception {
int keys = 1000;
int accsPerPerson = 4;
Ignite srv0 = ignite(0);
IgniteCache pers = srv0.createCache(personCacheConfiguration(grp1, "pers").setAffinity(new RendezvousAffinityFunction().setPartitions(10)).setCacheMode(cm1).setAtomicityMode(cam1));
IgniteCache acc = srv0.createCache(accountCacheConfiguration(grp2, "acc").setAffinity(new RendezvousAffinityFunction().setPartitions(10)).setCacheMode(cm2).setAtomicityMode(cam2));
try (Transaction tx = cam1 == TRANSACTIONAL || cam2 == TRANSACTIONAL ? srv0.transactions().txStart() : null) {
for (int i = 0; i < keys; i++) {
int pKey = i - (i % accsPerPerson);
if (i % accsPerPerson == 0)
pers.put(pKey, new Person("pers-" + pKey));
acc.put(new AffinityKey(i, pKey), new Account(pKey, "acc-" + i));
}
if (tx != null)
tx.commit();
}
Ignite node = ignite(2);
SqlFieldsQuery qry = new SqlFieldsQuery("select p._key as p_key, p.name, a._key as a_key, a.personId, a.attr \n" + "from \"pers\".Person p inner join \"acc\".Account a \n" + "on (p._key = a.personId)");
IgniteCache<Object, Object> cache = node.cache("acc");
List<List<?>> res = cache.query(qry).getAll();
assertEquals(keys, res.size());
for (List<?> row : res) assertEquals(row.get(0), row.get(3));
}
Aggregations