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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations