Search in sources :

Example 1 with Organization

use of org.apache.ignite.util.GridCommandHandlerIndexingUtils.Organization in project ignite by apache.

the class GridCommandHandlerIndexingCheckSizeTest method queryEntities.

/**
 * Creating {@link QueryEntity}'s with filling functions.
 *
 * @return {@link QueryEntity}'s with filling functions.
 */
private Map<QueryEntity, Function<Random, Object>> queryEntities() {
    Map<QueryEntity, Function<Random, Object>> qryEntities = new HashMap<>();
    qryEntities.put(personEntity(), rand -> new Person(rand.nextInt(), valueOf(rand.nextLong())));
    qryEntities.put(organizationEntity(), rand -> new Organization(rand.nextInt(), valueOf(rand.nextLong())));
    return qryEntities;
}
Also used : Function(java.util.function.Function) Organization(org.apache.ignite.util.GridCommandHandlerIndexingUtils.Organization) HashMap(java.util.HashMap) QueryEntity(org.apache.ignite.cache.QueryEntity) Person(org.apache.ignite.util.GridCommandHandlerIndexingUtils.Person)

Example 2 with Organization

use of org.apache.ignite.util.GridCommandHandlerIndexingUtils.Organization in project ignite by apache.

the class GridCommandHandlerIndexingCheckSizeTest method addColumnAndIdx.

/**
 * Adding the "address" column and index for {@link Person} and
 * {@link Organization}, with new entries added for each of them.
 *
 * @param node Node.
 * @param cacheName Cache name.
 * @param addCnt How many entries add to table.
 */
private void addColumnAndIdx(IgniteEx node, String cacheName, int addCnt) {
    IgniteCache<Object, Object> cache = node.cache(cacheName);
    cache.query(new SqlFieldsQuery("alter table Person add column orgAddr varchar")).getAll();
    cache.query(new SqlFieldsQuery("alter table Organization add column addr varchar")).getAll();
    cache.query(new SqlFieldsQuery("create index p_o_addr on Person (orgAddr)")).getAll();
    cache.query(new SqlFieldsQuery("create index o_addr on Organization (addr)")).getAll();
    int key = node.cachex(cacheName).size();
    try (IgniteDataStreamer<Object, Object> streamer = node.dataStreamer(cacheName)) {
        ThreadLocalRandom rand = ThreadLocalRandom.current();
        for (int i = 0; i < addCnt; i++) {
            streamer.addData(key++, new Person(rand.nextInt(), valueOf(rand.nextLong())).orgAddr(valueOf(rand.nextLong())));
            streamer.addData(key++, new Organization(rand.nextInt(), valueOf(rand.nextLong())).addr(valueOf(rand.nextLong())));
        }
        streamer.flush();
    }
}
Also used : Organization(org.apache.ignite.util.GridCommandHandlerIndexingUtils.Organization) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) Person(org.apache.ignite.util.GridCommandHandlerIndexingUtils.Person) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Aggregations

Organization (org.apache.ignite.util.GridCommandHandlerIndexingUtils.Organization)2 Person (org.apache.ignite.util.GridCommandHandlerIndexingUtils.Person)2 HashMap (java.util.HashMap)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 Function (java.util.function.Function)1 QueryEntity (org.apache.ignite.cache.QueryEntity)1 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)1 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)1