Search in sources :

Example 6 with QueryIndex

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

the class PlatformConfigurationUtils method readQueryEntity.

/**
     * Reads the query entity.
     *
     * @param in Stream.
     * @return QueryEntity.
     */
private static QueryEntity readQueryEntity(BinaryRawReader in) {
    QueryEntity res = new QueryEntity();
    res.setKeyType(in.readString());
    res.setValueType(in.readString());
    res.setTableName(in.readString());
    // Fields
    int cnt = in.readInt();
    Set<String> keyFields = new HashSet<>(cnt);
    if (cnt > 0) {
        LinkedHashMap<String, String> fields = new LinkedHashMap<>(cnt);
        for (int i = 0; i < cnt; i++) {
            String fieldName = in.readString();
            String fieldType = in.readString();
            fields.put(fieldName, fieldType);
            if (in.readBoolean())
                keyFields.add(fieldName);
        }
        res.setFields(fields);
        if (!keyFields.isEmpty())
            res.setKeyFields(keyFields);
    }
    // Aliases
    cnt = in.readInt();
    if (cnt > 0) {
        Map<String, String> aliases = new HashMap<>(cnt);
        for (int i = 0; i < cnt; i++) aliases.put(in.readString(), in.readString());
        res.setAliases(aliases);
    }
    // Indexes
    cnt = in.readInt();
    if (cnt > 0) {
        Collection<QueryIndex> indexes = new ArrayList<>(cnt);
        for (int i = 0; i < cnt; i++) indexes.add(readQueryIndex(in));
        res.setIndexes(indexes);
    }
    res.setKeyFieldName(in.readString());
    res.setValueFieldName(in.readString());
    return res;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with QueryIndex

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

the class H2IndexingAbstractGeoSelfTest method createCache.

/**
     * Create cache.
     *
     * @param name Name.
     * @param partitioned Partitioned flag.
     * @param keyCls Key class.
     * @param valCls Value class.
     * @param dynamicIdx Whether index should be created dynamically.
     * @return Cache.
     * @throws Exception If failed.
     */
@SuppressWarnings("unchecked")
protected <K, V> IgniteCache<K, V> createCache(String name, boolean partitioned, Class<?> keyCls, Class<?> valCls, boolean dynamicIdx) throws Exception {
    CacheConfiguration<K, V> ccfg = cacheConfig(name, partitioned, keyCls, valCls);
    if (dynamicIdx) {
        Collection<QueryEntity> entities = ccfg.getQueryEntities();
        assertEquals(1, entities.size());
        QueryEntity entity = entities.iterator().next();
        Collection<QueryIndex> idxs = new ArrayList<>(entity.getIndexes());
        entity.setIndexes(null);
        grid(0).context().cache().dynamicStartSqlCache(ccfg).get();
        IgniteCache<K, V> cache = grid(0).cache(name);
        // Process indexes dynamically.
        for (QueryIndex idx : idxs) {
            QueryEntity normalEntity = QueryUtils.normalizeQueryEntity(entity, ccfg.isSqlEscapeAll());
            createDynamicIndex(cache, normalEntity, idx);
        }
        return cache;
    } else
        return grid(0).getOrCreateCache(ccfg);
}
Also used : ArrayList(java.util.ArrayList) QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity)

Example 8 with QueryIndex

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

the class IgniteCacheJoinPartitionedAndReplicatedCollocationTest method accountCache.

/**
     * @param backups Number of backups.
     * @return Cache configuration.
     */
private CacheConfiguration accountCache(int backups) {
    CacheConfiguration ccfg = configuration(ACCOUNT_CACHE, backups);
    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")));
    ccfg.setQueryEntities(F.asList(entity));
    return ccfg;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 9 with QueryIndex

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

the class IgniteCacheJoinQueryWithAffinityKeyTest method cacheConfiguration.

/**
     * @param cacheMode Cache mode.
     * @param backups Number of backups.
     * @param affKey If {@code true} uses key with affinity key field.
     * @param includeAffKey If {@code true} includes affinity key field in query fields.
     * @return Cache configuration.
     */
private CacheConfiguration cacheConfiguration(CacheMode cacheMode, int backups, boolean affKey, boolean includeAffKey) {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setCacheMode(cacheMode);
    if (cacheMode == PARTITIONED)
        ccfg.setBackups(backups);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    String personKeyType = affKey ? TestKeyWithAffinity.class.getName() : TestKey.class.getName();
    QueryEntity account = new QueryEntity();
    account.setKeyType(Integer.class.getName());
    account.setValueType(affKey ? AccountKeyWithAffinity.class.getName() : Account.class.getName());
    account.addQueryField("personKey", personKeyType, null);
    account.addQueryField("personId", Integer.class.getName(), null);
    account.setIndexes(F.asList(new QueryIndex("personKey"), new QueryIndex("personId")));
    QueryEntity person = new QueryEntity();
    person.setKeyType(personKeyType);
    person.setValueType(Person.class.getName());
    person.addQueryField("orgId", Integer.class.getName(), null);
    person.addQueryField("id", Integer.class.getName(), null);
    person.addQueryField("name", String.class.getName(), null);
    person.setIndexes(F.asList(new QueryIndex("orgId"), new QueryIndex("id"), new QueryIndex("name")));
    if (affKey && includeAffKey)
        person.addQueryField("affKey", Integer.class.getName(), null);
    QueryEntity org = new QueryEntity();
    org.setKeyType(Integer.class.getName());
    org.setValueType(Organization.class.getName());
    org.addQueryField("name", String.class.getName(), null);
    org.setIndexes(F.asList(new QueryIndex("name")));
    ccfg.setQueryEntities(F.asList(account, person, org));
    ccfg.setSqlEscapeAll(escape);
    return ccfg;
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 10 with QueryIndex

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

the class IgniteCacheFullTextQueryNodeJoiningSelfTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    CacheConfiguration cache = new CacheConfiguration(DEFAULT_CACHE_NAME);
    cache.setCacheMode(PARTITIONED);
    cache.setAtomicityMode(atomicityMode());
    cache.setWriteSynchronizationMode(FULL_SYNC);
    cache.setBackups(1);
    QueryEntity qryEntity = new QueryEntity();
    qryEntity.setKeyType(AffinityKey.class.getName());
    qryEntity.setValueType(IndexedEntity.class.getName());
    LinkedHashMap<String, String> fields = new LinkedHashMap<>();
    fields.put("val", String.class.getName());
    qryEntity.setFields(fields);
    qryEntity.setIndexes(Arrays.asList(new QueryIndex("val", QueryIndexType.FULLTEXT)));
    cache.setQueryEntities(Arrays.asList(qryEntity));
    cfg.setCacheConfiguration(cache);
    TcpDiscoverySpi disco = new TcpDiscoverySpi();
    disco.setIpFinder(IP_FINDER);
    TcpCommunicationSpi commSpi = new TcpCommunicationSpi();
    commSpi.setSharedMemoryPort(-1);
    cfg.setCommunicationSpi(commSpi);
    cfg.setDiscoverySpi(disco);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) AffinityKey(org.apache.ignite.cache.affinity.AffinityKey) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) LinkedHashMap(java.util.LinkedHashMap) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

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