Search in sources :

Example 16 with CacheKeyConfiguration

use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.

the class IgnitePdsBinaryMetadataOnClusterRestartTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);
    cfg.setConsistentId(gridName);
    if (customWorkSubDir != null)
        cfg.setWorkDirectory(Paths.get(U.defaultWorkDirectory(), customWorkSubDir).toString());
    cfg.setDataStorageConfiguration(new DataStorageConfiguration().setWalMode(WALMode.LOG_ONLY).setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true).setMaxSize(100L * 1024 * 1024)));
    BinaryConfiguration bCfg = new BinaryConfiguration();
    BinaryTypeConfiguration binaryEnumCfg = new BinaryTypeConfiguration(EnumType.class.getName());
    binaryEnumCfg.setEnum(true);
    binaryEnumCfg.setEnumValues(F.asMap(EnumType.ENUM_VAL_0.name(), EnumType.ENUM_VAL_0.ordinal(), EnumType.ENUM_VAL_1.name(), EnumType.ENUM_VAL_1.ordinal()));
    bCfg.setTypeConfigurations(Arrays.asList(binaryEnumCfg));
    cfg.setBinaryConfiguration(bCfg);
    CacheKeyConfiguration dynamicMetaKeyCfg = new CacheKeyConfiguration(DYNAMIC_TYPE_NAME, DYNAMIC_INT_FIELD_NAME);
    cfg.setCacheKeyConfiguration(dynamicMetaKeyCfg);
    cfg.setCacheConfiguration(new CacheConfiguration().setName(CACHE_NAME).setAffinity(new RendezvousAffinityFunction()).setCacheMode(CacheMode.REPLICATED));
    return cfg;
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 17 with CacheKeyConfiguration

use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.

the class IgniteCacheDistributedJoinCollocatedAndNotTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(PersonKey.class.getName(), "affKey");
    cfg.setCacheKeyConfiguration(keyCfg);
    List<CacheConfiguration> ccfgs = new ArrayList<>();
    {
        CacheConfiguration ccfg = configuration(PERSON_CACHE);
        QueryEntity entity = new QueryEntity();
        entity.setKeyType(PersonKey.class.getName());
        entity.setValueType(Person.class.getName());
        entity.addQueryField("id", Integer.class.getName(), null);
        entity.addQueryField("affKey", Integer.class.getName(), null);
        entity.addQueryField("name", String.class.getName(), null);
        entity.setKeyFields(new HashSet<>(Arrays.asList("id", "affKey")));
        ccfg.setQueryEntities(F.asList(entity));
        ccfgs.add(ccfg);
    }
    {
        CacheConfiguration ccfg = configuration(ORG_CACHE);
        QueryEntity entity = new QueryEntity();
        entity.setKeyType(Integer.class.getName());
        entity.setValueType(Organization.class.getName());
        entity.addQueryField("name", String.class.getName(), null);
        entity.setIndexes(F.asList(new QueryIndex("name")));
        ccfg.setQueryEntities(F.asList(entity));
        ccfgs.add(ccfg);
    }
    {
        CacheConfiguration ccfg = configuration(ACCOUNT_CACHE);
        QueryEntity entity = new QueryEntity();
        entity.setKeyType(Integer.class.getName());
        entity.setValueType(Account.class.getName());
        entity.addQueryField("personId", Integer.class.getName(), null);
        entity.addQueryField("name", String.class.getName(), null);
        entity.setIndexes(F.asList(new QueryIndex("personId"), new QueryIndex("name")));
        ccfg.setQueryEntities(F.asList(entity));
        ccfgs.add(ccfg);
    }
    cfg.setCacheConfiguration(ccfgs.toArray(new CacheConfiguration[ccfgs.size()]));
    return cfg;
}
Also used : CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ArrayList(java.util.ArrayList) QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) HashSet(java.util.HashSet)

Example 18 with CacheKeyConfiguration

use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.

the class PojoIndexLocalQueryTest method localPojoReproducerTest.

/**
 */
@Test
public void localPojoReproducerTest() {
    String tblName = TestPojo.class.getSimpleName().toUpperCase() + "_TBL" + TBL_ID.incrementAndGet();
    Class<?> keyCls = TestKeyWithIdx.class;
    Class<?> idxCls = TestPojo.class;
    // Create cache
    LinkedHashMap<String, String> fields = new LinkedHashMap<>(2);
    fields.put("idxVal", idxCls.getName());
    fields.put("val", Integer.class.getName());
    QueryEntity qe = new QueryEntity(keyCls.getName(), Integer.class.getName()).setTableName(tblName).setValueFieldName("val").setFields(fields);
    String idxName = "IDXVAL_IDX";
    String idxFieldName = "idxVal";
    qe.setKeyFields(Collections.singleton(idxFieldName));
    qe.setIndexes(Collections.singleton(new QueryIndex(idxFieldName, true, idxName)));
    IgniteCache<Object, Integer> cache = grid(0).createCache(new CacheConfiguration<Object, Integer>(tblName + "_CACHE").setKeyConfiguration(new CacheKeyConfiguration((TestKeyWithIdx.class).getName(), "idxVal")).setQueryEntities(Collections.singletonList(qe)).setSqlSchema("PUBLIC"));
    int[] a1 = { -903, 141, 202 };
    int[] b1 = { -876, 765, -192 };
    int[] c1 = { -726, 109, -182 };
    TestPojo pojo1 = new TestPojo(b1[0]);
    TestPojo pojo2 = new TestPojo(b1[1]);
    TestPojo pojo3 = new TestPojo(b1[2]);
    TestKeyWithIdx<TestPojo> idx1 = new TestKeyWithIdx<>(a1[0], pojo1);
    TestKeyWithIdx<TestPojo> idx2 = new TestKeyWithIdx<>(a1[1], pojo2);
    TestKeyWithIdx<TestPojo> idx3 = new TestKeyWithIdx<>(a1[2], pojo3);
    cache.put(idx1, c1[0]);
    cache.put(idx2, c1[1]);
    cache.put(idx3, c1[2]);
    String format = String.format(SELECT_VALUE_TEMPLATE, tblName, idxName, idxFieldName);
    List<List<?>> sqlRes = grid(0).context().query().querySqlFields(new SqlFieldsQuery(format).setArgs(pojo3).setLocal(true), false).getAll();
    assertEquals(1, sqlRes.size());
    Integer val = cache.get(idx3);
    assertEquals(val, sqlRes.get(0).get(0));
    grid(0).destroyCache(tblName + "_CACHE");
}
Also used : CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) QueryEntity(org.apache.ignite.cache.QueryEntity) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) LinkedHashMap(java.util.LinkedHashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueryIndex(org.apache.ignite.cache.QueryIndex) List(java.util.List) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test)

Example 19 with CacheKeyConfiguration

use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.

the class IgniteCacheJoinQueryWithAffinityKeyTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    CacheKeyConfiguration keyCfg = new CacheKeyConfiguration();
    keyCfg.setTypeName(TestKeyWithAffinity.class.getName());
    keyCfg.setAffinityKeyFieldName("affKey");
    cfg.setCacheKeyConfiguration(keyCfg);
    return cfg;
}
Also used : CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration)

Example 20 with CacheKeyConfiguration

use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.

the class JoinQueryEntityPartitionPruningSelfTest method checkAffinityFunctions.

/**
 * @param ccfg1 Cache config 1.
 * @param ccfg2 Cache config 2.
 * @param compatible Compatible affinity function flag (false when affinity is incompatible).
 */
@SuppressWarnings("unchecked")
private void checkAffinityFunctions(CacheConfiguration ccfg1, CacheConfiguration ccfg2, boolean compatible) {
    // Destroy old caches.
    Ignite cli = client();
    cli.destroyCaches(cli.cacheNames());
    // Start new caches.
    ccfg1.setName("t1");
    ccfg2.setName("t2");
    QueryEntity entity1 = new QueryEntity(KeyClass1.class, ValueClass.class).setTableName("t1");
    QueryEntity entity2 = new QueryEntity(KeyClass2.class, ValueClass.class).setTableName("t2");
    ccfg1.setQueryEntities(Collections.singletonList(entity1));
    ccfg2.setQueryEntities(Collections.singletonList(entity2));
    ccfg1.setKeyConfiguration(new CacheKeyConfiguration(entity1.getKeyType(), "k1"));
    ccfg2.setKeyConfiguration(new CacheKeyConfiguration(entity2.getKeyType(), "ak2"));
    ccfg1.setSqlSchema(QueryUtils.DFLT_SCHEMA);
    ccfg2.setSqlSchema(QueryUtils.DFLT_SCHEMA);
    client().createCache(ccfg1);
    client().createCache(ccfg2);
    // Conduct tests.
    execute("SELECT * FROM t1 INNER JOIN t2 ON t1.k1 = t2.ak2 WHERE t1.k1 = ?", (res) -> assertPartitions(partition("t1", "1")), "1");
    execute("SELECT * FROM t1 INNER JOIN t2 ON t1.k1 = t2.ak2 WHERE t2.ak2 = ?", (res) -> assertPartitions(partition("t2", "2")), "2");
    if (compatible) {
        execute("SELECT * FROM t1 INNER JOIN t2 ON t1.k1 = t2.ak2 WHERE t1.k1 = ? OR t2.ak2 = ?", (res) -> assertPartitions(partition("t1", "1"), partition("t2", "2")), "1", "2");
    } else {
        execute("SELECT * FROM t1 INNER JOIN t2 ON t1.k1 = t2.ak2 WHERE t1.k1 = ? OR t2.ak2 = ?", (res) -> assertNoPartitions(), "1", "2");
    }
}
Also used : CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) Ignite(org.apache.ignite.Ignite) QueryEntity(org.apache.ignite.cache.QueryEntity)

Aggregations

CacheKeyConfiguration (org.apache.ignite.cache.CacheKeyConfiguration)41 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)24 QueryEntity (org.apache.ignite.cache.QueryEntity)19 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)17 ArrayList (java.util.ArrayList)11 LinkedHashMap (java.util.LinkedHashMap)7 QueryIndex (org.apache.ignite.cache.QueryIndex)7 Ignite (org.apache.ignite.Ignite)6 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)6 HashMap (java.util.HashMap)5 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)5 Map (java.util.Map)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)4 SimpleEntry (java.util.AbstractMap.SimpleEntry)3 Collectors (java.util.stream.Collectors)3 BinaryObject (org.apache.ignite.binary.BinaryObject)3 CacheAtomicityMode (org.apache.ignite.cache.CacheAtomicityMode)3 CacheMode (org.apache.ignite.cache.CacheMode)3 CacheRebalanceMode (org.apache.ignite.cache.CacheRebalanceMode)3