Search in sources :

Example 21 with QueryIndex

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

the class IgniteCacheAbstractQuerySelfTest method cacheConfiguration.

/**
     * @return cache configuration
     */
protected CacheConfiguration cacheConfiguration() {
    CacheConfiguration cc = defaultCacheConfiguration();
    cc.setCacheMode(cacheMode());
    cc.setAtomicityMode(atomicityMode());
    cc.setNearConfiguration(nearCacheConfiguration());
    cc.setWriteSynchronizationMode(FULL_SYNC);
    cc.setCacheStoreFactory(new StoreFactory());
    cc.setReadThrough(true);
    cc.setWriteThrough(true);
    cc.setLoadPreviousValue(true);
    cc.setRebalanceMode(SYNC);
    cc.setSqlFunctionClasses(SqlFunctions.class);
    List<QueryEntity> entityList = new ArrayList<>();
    QueryEntity qryEntity = new QueryEntity();
    qryEntity.setKeyType(Integer.class.getName());
    qryEntity.setValueType(Type1.class.getName());
    qryEntity.addQueryField("id", Integer.class.getName(), null);
    qryEntity.addQueryField("name", String.class.getName(), null);
    qryEntity.setTableName("Type2");
    qryEntity.setIndexes(Arrays.asList(new QueryIndex("id")));
    entityList.add(qryEntity);
    qryEntity = new QueryEntity();
    qryEntity.setKeyType(Integer.class.getName());
    qryEntity.setValueType(Type2.class.getName());
    qryEntity.addQueryField("id", Integer.class.getName(), null);
    qryEntity.addQueryField("name", String.class.getName(), null);
    qryEntity.setTableName("Type1");
    qryEntity.setIndexes(Arrays.asList(new QueryIndex("id")));
    entityList.add(qryEntity);
    qryEntity = new QueryEntity();
    qryEntity.setKeyType(Integer.class.getName());
    qryEntity.setValueType(ObjectValue2.class.getName());
    qryEntity.addQueryField("strVal", String.class.getName(), null);
    // Default index type
    final QueryIndex strIdx = new QueryIndex();
    strIdx.setFieldNames(Collections.singletonList("strVal"), true);
    qryEntity.setIndexes(Arrays.asList(strIdx));
    entityList.add(qryEntity);
    cc.setQueryEntities(entityList);
    if (cacheMode() != CacheMode.LOCAL)
        cc.setAffinity(new RendezvousAffinityFunction());
    // Explicitly set number of backups equal to number of grids.
    if (cacheMode() == CacheMode.PARTITIONED)
        cc.setBackups(gridCount());
    return cc;
}
Also used : ArrayList(java.util.ArrayList) QueryIndex(org.apache.ignite.cache.QueryIndex) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) QueryEntity(org.apache.ignite.cache.QueryEntity) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 22 with QueryIndex

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

the class ClientReconnectAfterClusterRestartTest method getCacheConfiguration.

/**
     * @return CacheConfiguration Cache configuration.
     */
@NotNull
private CacheConfiguration getCacheConfiguration() {
    CacheConfiguration ccfg = defaultCacheConfiguration();
    ccfg.setName(CACHE_PARAMS);
    ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
    ccfg.setCacheMode(CacheMode.PARTITIONED);
    List<QueryEntity> queryEntities = new ArrayList<>();
    QueryEntity entity = new QueryEntity();
    entity.setValueType("Params");
    entity.setKeyType("java.lang.Long");
    LinkedHashMap<String, String> fields = new LinkedHashMap<>();
    fields.put("ID", "java.lang.Long");
    fields.put("PARTITIONID", "java.lang.Long");
    fields.put("CLIENTID", "java.lang.Long");
    fields.put("PARAMETRCODE", "java.lang.Long");
    fields.put("PARAMETRVALUE", "java.lang.Object");
    fields.put("PARENTID", "java.lang.Long");
    entity.setFields(fields);
    List<QueryIndex> indexes = new ArrayList<>();
    indexes.add(new QueryIndex("CLIENTID"));
    indexes.add(new QueryIndex("ID"));
    indexes.add(new QueryIndex("PARENTID"));
    entity.setIndexes(indexes);
    queryEntities.add(entity);
    ccfg.setQueryEntities(queryEntities);
    return ccfg;
}
Also used : ArrayList(java.util.ArrayList) QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) LinkedHashMap(java.util.LinkedHashMap) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with QueryIndex

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

the class IgniteCrossCachesJoinsQueryTest method cacheConfiguration.

/**
     * @param cacheName Cache name.
     * @param cacheMode Cache mode.
     * @param backups Number of backups.
     * @param idx Index flag.
     * @param accountCache Account cache flag.
     * @param personCache Person cache flag.
     * @param orgCache Organization cache flag.
     * @return Cache configuration.
     */
private CacheConfiguration cacheConfiguration(String cacheName, CacheMode cacheMode, int backups, boolean idx, boolean accountCache, boolean personCache, boolean orgCache) {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setName(cacheName);
    ccfg.setCacheMode(cacheMode);
    if (cacheMode == PARTITIONED)
        ccfg.setBackups(backups);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    List<QueryEntity> entities = new ArrayList<>();
    if (accountCache) {
        QueryEntity account = new QueryEntity();
        account.setKeyType(useCollocatedData() ? AffinityKey.class.getName() : Integer.class.getName());
        account.setValueType(Account.class.getName());
        account.addQueryField("id", Integer.class.getName(), null);
        account.addQueryField("personId", Integer.class.getName(), null);
        account.addQueryField("personDateId", Date.class.getName(), null);
        account.addQueryField("personStrId", String.class.getName(), null);
        if (idx) {
            account.setIndexes(F.asList(new QueryIndex("id"), new QueryIndex("personId"), new QueryIndex("personDateId"), new QueryIndex("personStrId")));
        }
        entities.add(account);
    }
    if (personCache) {
        QueryEntity person = new QueryEntity();
        person.setKeyType(useCollocatedData() ? AffinityKey.class.getName() : Integer.class.getName());
        person.setValueType(Person.class.getName());
        person.addQueryField("id", Integer.class.getName(), null);
        person.addQueryField("dateId", Date.class.getName(), null);
        person.addQueryField("strId", String.class.getName(), null);
        person.addQueryField("orgId", Integer.class.getName(), null);
        person.addQueryField("orgDateId", Date.class.getName(), null);
        person.addQueryField("orgStrId", String.class.getName(), null);
        person.addQueryField("name", String.class.getName(), null);
        person.addQueryField("salary", Integer.class.getName(), null);
        if (idx) {
            person.setIndexes(F.asList(new QueryIndex("id"), new QueryIndex("dateId"), new QueryIndex("strId"), new QueryIndex("orgId"), new QueryIndex("orgDateId"), new QueryIndex("orgStrId"), new QueryIndex("name"), new QueryIndex("salary")));
        }
        entities.add(person);
    }
    if (orgCache) {
        QueryEntity org = new QueryEntity();
        org.setKeyType(Integer.class.getName());
        org.setValueType(Organization.class.getName());
        org.addQueryField("id", Integer.class.getName(), null);
        org.addQueryField("dateId", Date.class.getName(), null);
        org.addQueryField("strId", String.class.getName(), null);
        org.addQueryField("name", String.class.getName(), null);
        if (idx) {
            org.setIndexes(F.asList(new QueryIndex("id"), new QueryIndex("dateId"), new QueryIndex("strId"), new QueryIndex("name")));
        }
        entities.add(org);
    }
    ccfg.setQueryEntities(entities);
    return ccfg;
}
Also used : ArrayList(java.util.ArrayList) QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Date(java.util.Date)

Example 24 with QueryIndex

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

the class AbstractSchemaSelfTest method assertIndexDescriptor.

/**
     * Make sure index exists in cache descriptor.
     *
     * @param node Node.
     * @param cacheName Cache name.
     * @param tblName Table name.
     * @param idxName Index name.
     * @param fields Fields.
     */
protected static void assertIndexDescriptor(IgniteEx node, String cacheName, String tblName, String idxName, IgniteBiTuple<String, Boolean>... fields) {
    awaitCompletion();
    DynamicCacheDescriptor desc = node.context().cache().cacheDescriptor(cacheName);
    assert desc != null;
    for (QueryEntity entity : desc.schema().entities()) {
        if (F.eq(tblName, entity.getTableName())) {
            for (QueryIndex idx : entity.getIndexes()) {
                if (F.eq(QueryUtils.indexName(entity, idx), idxName)) {
                    LinkedHashMap<String, Boolean> idxFields = idx.getFields();
                    assertEquals(idxFields.size(), fields.length);
                    int i = 0;
                    for (String idxField : idxFields.keySet()) {
                        assertEquals(idxField.toLowerCase(), fields[i].get1().toLowerCase());
                        assertEquals(idxFields.get(idxField), fields[i].get2());
                        i++;
                    }
                    return;
                }
            }
        }
    }
    fail("Index not found [node=" + node.name() + ", cacheName=" + cacheName + ", tlbName=" + tblName + ", idxName=" + idxName + ']');
}
Also used : DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity)

Example 25 with QueryIndex

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

the class DynamicIndexAbstractBasicSelfTest method checkCreateNoTable.

/**
     * Check create when table doesn't exist.
     *
     * @param mode Mode.
     * @param atomicityMode Atomicity mode.
     * @param near Near flag.
     * @throws Exception If failed.
     */
private void checkCreateNoTable(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
    initialize(mode, atomicityMode, near);
    final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1_ESCAPED));
    assertSchemaException(new RunnableX() {

        @Override
        public void run() throws Exception {
            dynamicIndexCreate(CACHE_NAME, randomString(), idx, false);
        }
    }, IgniteQueryErrorCode.TABLE_NOT_FOUND);
    assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) CacheException(javax.cache.CacheException)

Aggregations

QueryIndex (org.apache.ignite.cache.QueryIndex)69 QueryEntity (org.apache.ignite.cache.QueryEntity)35 LinkedHashMap (java.util.LinkedHashMap)25 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)21 ArrayList (java.util.ArrayList)18 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)16 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 Ignite (org.apache.ignite.Ignite)13 IgniteException (org.apache.ignite.IgniteException)8 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)8 HashMap (java.util.HashMap)7 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)7 CacheException (javax.cache.CacheException)6 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)6 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 HashSet (java.util.HashSet)4 Map (java.util.Map)4 BinaryObject (org.apache.ignite.binary.BinaryObject)4