Search in sources :

Example 51 with QueryEntity

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

the class IgniteSqlKeyValueFieldsTest method buildCacheConfiguration.

private CacheConfiguration buildCacheConfiguration(String name) {
    if (name.equals(NODE_BAD_CONF_MISS_KEY_FIELD)) {
        CacheConfiguration ccfg = new CacheConfiguration(NODE_BAD_CONF_MISS_KEY_FIELD);
        QueryEntity qe = new QueryEntity(Object.class.getName(), Object.class.getName());
        qe.setKeyFieldName("k");
        qe.addQueryField("a", Integer.class.getName(), null);
        ccfg.setQueryEntities(F.asList(qe));
        return ccfg;
    } else if (name.equals(NODE_BAD_CONF_MISS_VAL_FIELD)) {
        CacheConfiguration ccfg = new CacheConfiguration(NODE_BAD_CONF_MISS_VAL_FIELD);
        QueryEntity qe = new QueryEntity(Object.class.getName(), Object.class.getName());
        qe.setValueFieldName("v");
        qe.addQueryField("a", Integer.class.getName(), null);
        ccfg.setQueryEntities(F.asList(qe));
        return ccfg;
    } else if (name.equals(CACHE_PERSON_NO_KV)) {
        CacheConfiguration ccfg = new CacheConfiguration(CACHE_PERSON_NO_KV);
        QueryEntity entity = new QueryEntity();
        entity.setKeyType(Integer.class.getName());
        entity.setValueType(Person.class.getName());
        LinkedHashMap<String, String> fields = new LinkedHashMap<>();
        fields.put("name", String.class.getName());
        fields.put("age", Integer.class.getName());
        entity.setFields(fields);
        ccfg.setQueryEntities(Arrays.asList(entity));
        return ccfg;
    } else if (name.equals(CACHE_INT_NO_KV_TYPE)) {
        CacheConfiguration ccfg = new CacheConfiguration(CACHE_INT_NO_KV_TYPE);
        QueryEntity entity = new QueryEntity();
        entity.setKeyType(null);
        entity.setValueType(null);
        entity.setKeyFieldName("id");
        entity.setValueFieldName("v");
        LinkedHashMap<String, String> fields = new LinkedHashMap<>();
        fields.put("id", Integer.class.getName());
        fields.put("v", Integer.class.getName());
        entity.setFields(fields);
        ccfg.setQueryEntities(Arrays.asList(entity));
        return ccfg;
    } else if (name.equals(CACHE_PERSON)) {
        CacheConfiguration ccfg = new CacheConfiguration(CACHE_PERSON);
        QueryEntity entity = new QueryEntity();
        entity.setKeyType(Integer.class.getName());
        entity.setValueType(Person.class.getName());
        entity.setKeyFieldName("id");
        entity.setValueFieldName("v");
        LinkedHashMap<String, String> fields = new LinkedHashMap<>();
        fields.put("name", String.class.getName());
        fields.put("age", Integer.class.getName());
        fields.put(entity.getKeyFieldName(), entity.getKeyType());
        fields.put(entity.getValueFieldName(), entity.getValueType());
        entity.setFields(fields);
        ccfg.setQueryEntities(Arrays.asList(entity));
        return ccfg;
    } else if (name.equals(CACHE_JOB)) {
        CacheConfiguration ccfg = new CacheConfiguration(CACHE_JOB);
        ccfg.setIndexedTypes(Integer.class, Integer.class);
        return ccfg;
    }
    return null;
}
Also used : QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) LinkedHashMap(java.util.LinkedHashMap)

Example 52 with QueryEntity

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

the class AbstractSchemaSelfTest method assertNoIndexDescriptor.

/**
     * Assert index doesn't exist in particular node's cache descriptor.
     *
     * @param node Node.
     * @param cacheName Cache name.
     * @param idxName Index name.
     */
protected static void assertNoIndexDescriptor(IgniteEx node, String cacheName, String idxName) {
    awaitCompletion();
    DynamicCacheDescriptor desc = node.context().cache().cacheDescriptor(cacheName);
    if (desc == null)
        return;
    for (QueryEntity entity : desc.schema().entities()) {
        for (QueryIndex idx : entity.getIndexes()) {
            if (F.eq(idxName, QueryUtils.indexName(entity, idx)))
                fail("Index exists: " + idxName);
        }
    }
}
Also used : DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity)

Example 53 with QueryEntity

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

the class GridCacheProcessor method initialize.

/**
     * @param cfg Initializes cache configuration with proper defaults.
     * @param cacheObjCtx Cache object context.
     * @throws IgniteCheckedException If configuration is not valid.
     */
private void initialize(CacheConfiguration cfg, CacheObjectContext cacheObjCtx) throws IgniteCheckedException {
    if (cfg.getCacheMode() == null)
        cfg.setCacheMode(DFLT_CACHE_MODE);
    if (cfg.getNodeFilter() == null)
        cfg.setNodeFilter(CacheConfiguration.ALL_NODES);
    if (cfg.getAffinity() == null) {
        if (cfg.getCacheMode() == PARTITIONED) {
            RendezvousAffinityFunction aff = new RendezvousAffinityFunction();
            cfg.setAffinity(aff);
        } else if (cfg.getCacheMode() == REPLICATED) {
            RendezvousAffinityFunction aff = new RendezvousAffinityFunction(false, 512);
            cfg.setAffinity(aff);
            cfg.setBackups(Integer.MAX_VALUE);
        } else
            cfg.setAffinity(new LocalAffinityFunction());
    } else {
        if (cfg.getCacheMode() == LOCAL && !(cfg.getAffinity() instanceof LocalAffinityFunction)) {
            cfg.setAffinity(new LocalAffinityFunction());
            U.warn(log, "AffinityFunction configuration parameter will be ignored for local cache" + " [cacheName=" + U.maskName(cfg.getName()) + ']');
        }
    }
    if (cfg.getCacheMode() == REPLICATED)
        cfg.setBackups(Integer.MAX_VALUE);
    if (cfg.getQueryParallelism() > 1 && cfg.getCacheMode() != PARTITIONED)
        throw new IgniteCheckedException("Segmented indices are supported for PARTITIONED mode only.");
    if (cfg.getAffinityMapper() == null)
        cfg.setAffinityMapper(cacheObjCtx.defaultAffMapper());
    ctx.igfsHelper().preProcessCacheConfiguration(cfg);
    if (cfg.getRebalanceMode() == null)
        cfg.setRebalanceMode(ASYNC);
    if (cfg.getAtomicityMode() == null)
        cfg.setAtomicityMode(CacheConfiguration.DFLT_CACHE_ATOMICITY_MODE);
    if (cfg.getWriteSynchronizationMode() == null)
        cfg.setWriteSynchronizationMode(PRIMARY_SYNC);
    assert cfg.getWriteSynchronizationMode() != null;
    if (cfg.getCacheStoreFactory() == null) {
        Factory<CacheLoader> ldrFactory = cfg.getCacheLoaderFactory();
        Factory<CacheWriter> writerFactory = cfg.isWriteThrough() ? cfg.getCacheWriterFactory() : null;
        if (ldrFactory != null || writerFactory != null)
            cfg.setCacheStoreFactory(new GridCacheLoaderWriterStoreFactory(ldrFactory, writerFactory));
    } else {
        if (cfg.getCacheLoaderFactory() != null)
            throw new IgniteCheckedException("Cannot set both cache loaded factory and cache store factory " + "for cache: " + U.maskName(cfg.getName()));
        if (cfg.getCacheWriterFactory() != null)
            throw new IgniteCheckedException("Cannot set both cache writer factory and cache store factory " + "for cache: " + U.maskName(cfg.getName()));
    }
    Collection<QueryEntity> entities = cfg.getQueryEntities();
    if (!F.isEmpty(entities)) {
        Collection<QueryEntity> normalEntities = new ArrayList<>(entities.size());
        for (QueryEntity entity : entities) normalEntities.add(QueryUtils.normalizeQueryEntity(entity, cfg.isSqlEscapeAll()));
        cfg.clearQueryEntities().setQueryEntities(normalEntities);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheWriter(javax.cache.integration.CacheWriter) ArrayList(java.util.ArrayList) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheLoader(javax.cache.integration.CacheLoader) QueryEntity(org.apache.ignite.cache.QueryEntity)

Example 54 with QueryEntity

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

the class CacheConfiguration method convert.

/**
     * @param desc Type descriptor.
     * @return Type metadata.
     */
private static QueryEntity convert(TypeDescriptor desc) {
    QueryEntity entity = new QueryEntity();
    // Key and val types.
    entity.setKeyType(desc.keyClass().getName());
    entity.setValueType(desc.valueClass().getName());
    for (ClassProperty prop : desc.props.values()) entity.addQueryField(prop.fullName(), U.box(prop.type()).getName(), prop.alias());
    entity.setKeyFields(desc.keyProps);
    QueryIndex txtIdx = null;
    Collection<QueryIndex> idxs = new ArrayList<>();
    for (Map.Entry<String, GridQueryIndexDescriptor> idxEntry : desc.indexes().entrySet()) {
        GridQueryIndexDescriptor idx = idxEntry.getValue();
        if (idx.type() == QueryIndexType.FULLTEXT) {
            assert txtIdx == null;
            txtIdx = new QueryIndex();
            txtIdx.setIndexType(QueryIndexType.FULLTEXT);
            txtIdx.setFieldNames(idx.fields(), true);
            txtIdx.setName(idxEntry.getKey());
        } else {
            Collection<String> grp = new ArrayList<>();
            for (String fieldName : idx.fields()) grp.add(idx.descending(fieldName) ? fieldName + " desc" : fieldName);
            QueryIndex sortedIdx = new QueryIndex();
            sortedIdx.setIndexType(idx.type());
            LinkedHashMap<String, Boolean> fields = new LinkedHashMap<>();
            for (String f : idx.fields()) fields.put(f, !idx.descending(f));
            sortedIdx.setFields(fields);
            sortedIdx.setName(idxEntry.getKey());
            idxs.add(sortedIdx);
        }
    }
    if (desc.valueTextIndex()) {
        if (txtIdx == null) {
            txtIdx = new QueryIndex();
            txtIdx.setIndexType(QueryIndexType.FULLTEXT);
            txtIdx.setFieldNames(Arrays.asList(QueryUtils.VAL_FIELD_NAME), true);
        } else
            txtIdx.getFields().put(QueryUtils.VAL_FIELD_NAME, true);
    }
    if (txtIdx != null)
        idxs.add(txtIdx);
    if (!F.isEmpty(idxs))
        entity.setIndexes(idxs);
    return entity;
}
Also used : ArrayList(java.util.ArrayList) QueryEntity(org.apache.ignite.cache.QueryEntity) LinkedHashMap(java.util.LinkedHashMap) QueryIndex(org.apache.ignite.cache.QueryIndex) GridQueryIndexDescriptor(org.apache.ignite.internal.processors.query.GridQueryIndexDescriptor) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 55 with QueryEntity

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

the class GridCacheQuerySqlFieldInlineSizeSelfTest method testGroupIndex.

/**
 * @throws Exception If failed.
 */
public void testGroupIndex() throws Exception {
    CacheConfiguration ccfg = defaultCacheConfiguration();
    ccfg.setIndexedTypes(Integer.class, TestValueGroupIndex.class);
    assertEquals(1, ccfg.getQueryEntities().size());
    QueryEntity ent = (QueryEntity) ccfg.getQueryEntities().iterator().next();
    assertEquals(1, ent.getIndexes().size());
    QueryIndex idx = ent.getIndexes().iterator().next();
    assertEquals(10, idx.getInlineSize());
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

QueryEntity (org.apache.ignite.cache.QueryEntity)97 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)59 QueryIndex (org.apache.ignite.cache.QueryIndex)46 LinkedHashMap (java.util.LinkedHashMap)38 ArrayList (java.util.ArrayList)33 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)17 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)12 HashSet (java.util.HashSet)8 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)8 HashMap (java.util.HashMap)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 CacheKeyConfiguration (org.apache.ignite.cache.CacheKeyConfiguration)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 BinaryObject (org.apache.ignite.binary.BinaryObject)5 DynamicCacheDescriptor (org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor)5 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)4 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)4 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)4 List (java.util.List)3 Map (java.util.Map)3