use of org.apache.ignite.cache.QueryIndex in project ignite by apache.
the class LongIndexNameTest method getIndexCfg.
/**
*/
public static List<QueryEntity> getIndexCfg() {
ArrayList<QueryEntity> entities = new ArrayList<>();
QueryEntity qe = new QueryEntity(String.class.getName(), Person.class.getName());
LinkedHashMap<String, String> fieldsMap = new LinkedHashMap<>();
fieldsMap.put("name", String.class.getName());
fieldsMap.put("age", Integer.class.getName());
qe.setFields(fieldsMap);
ArrayList<QueryIndex> indices = new ArrayList<>();
QueryIndex index = new QueryIndex("name", true, "LONG_NAME_123456789012345678901234567890" + "12345678901234567890123456789012345678901234567890123456789012345678901234567890");
QueryIndex index2 = new QueryIndex("age", true, "AGE_IDX");
indices.add(index);
indices.add(index2);
qe.setIndexes(indices);
entities.add(qe);
return entities;
}
use of org.apache.ignite.cache.QueryIndex in project ignite by apache.
the class QueryEntityValidationSelfTest method testIndexNameDuplicate.
/**
* Test duplicated index name.
*
* @throws Exception If failed.
*/
public void testIndexNameDuplicate() throws Exception {
final CacheConfiguration ccfg = new CacheConfiguration().setName(CACHE_NAME);
QueryEntity entity = new QueryEntity();
entity.setKeyType("Key");
entity.setValueType("Value");
LinkedHashMap<String, String> fields = new LinkedHashMap<>();
fields.put("a", Integer.class.getName());
fields.put("b", Integer.class.getName());
entity.setFields(fields);
LinkedHashMap<String, Boolean> idx1Fields = new LinkedHashMap<>();
LinkedHashMap<String, Boolean> idx2Fields = new LinkedHashMap<>();
idx1Fields.put("a", true);
idx1Fields.put("b", true);
QueryIndex idx1 = new QueryIndex().setName("idx").setFields(idx1Fields);
QueryIndex idx2 = new QueryIndex().setName("idx").setFields(idx2Fields);
List<QueryIndex> idxs = new ArrayList<>();
idxs.add(idx1);
idxs.add(idx2);
entity.setIndexes(idxs);
ccfg.setQueryEntities(Collections.singleton(entity));
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
grid(0).createCache(ccfg);
return null;
}
}, IgniteCheckedException.class, "Duplicate index name");
}
use of org.apache.ignite.cache.QueryIndex in project ignite by apache.
the class SchemaExchangeSelfTest method testClientReconnect.
/**
* Test client reconnect.
*
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
public void testClientReconnect() throws Exception {
final IgniteEx node1 = start(1, KeyClass.class, ValueClass.class);
assertTypes(node1, ValueClass.class);
final IgniteEx node2 = startClientNoCache(2);
assertTypes(node2);
node2.cache(CACHE_NAME);
assertTypes(node2, ValueClass.class);
reconnectClientNode(log, node2, node1, new Runnable() {
@Override
public void run() {
assertTrue(node2.context().clientDisconnected());
final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1_ESCAPED));
try {
dynamicIndexCreate(node1, CACHE_NAME, TBL_NAME, idx, false, 0);
} catch (Exception e) {
throw new IgniteException(e);
}
}
});
assertIndex(CACHE_NAME, QueryUtils.normalizeObjectName(TBL_NAME, true), QueryUtils.normalizeObjectName(IDX_NAME_1, false), QueryIndex.DFLT_INLINE_SIZE, field(QueryUtils.normalizeObjectName(FIELD_NAME_1_ESCAPED, false)));
}
use of org.apache.ignite.cache.QueryIndex in project ignite by apache.
the class JdbcMetadataSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
LinkedHashMap<String, Boolean> persFields = new LinkedHashMap<>();
persFields.put("name", true);
persFields.put("age", false);
cfg.setCacheConfiguration(cacheConfiguration("pers").setQueryEntities(Arrays.asList(new QueryEntityEx(new QueryEntity(AffinityKey.class.getName(), Person.class.getName()).addQueryField("name", String.class.getName(), null).addQueryField("age", Integer.class.getName(), null).addQueryField("orgId", Integer.class.getName(), null).setIndexes(Arrays.asList(new QueryIndex("orgId"), new QueryIndex().setFields(persFields)))).setNotNullFields(new HashSet<>(Arrays.asList("age", "name"))))), cacheConfiguration("org").setQueryEntities(Arrays.asList(new QueryEntity(AffinityKey.class, Organization.class))));
TcpDiscoverySpi disco = new TcpDiscoverySpi();
disco.setIpFinder(IP_FINDER);
cfg.setDiscoverySpi(disco);
cfg.setConnectorConfiguration(new ConnectorConfiguration());
return cfg;
}
use of org.apache.ignite.cache.QueryIndex in project ignite by apache.
the class QueryUtils method checkQueryEntityConflicts.
/**
* Check given {@link CacheConfiguration} for conflicts in table and index names from any query entities
* found in collection of {@link DynamicCacheDescriptor}s and belonging to the same schema.
*
* @param ccfg New cache configuration.
* @param descs Cache descriptors.
* @return Exception message describing found conflict or {@code null} if none found.
*/
public static SchemaOperationException checkQueryEntityConflicts(CacheConfiguration<?, ?> ccfg, Collection<DynamicCacheDescriptor> descs) {
String schema = QueryUtils.normalizeSchemaName(ccfg.getName(), ccfg.getSqlSchema());
Set<String> idxNames = new HashSet<>();
Set<String> tblNames = new HashSet<>();
for (DynamicCacheDescriptor desc : descs) {
if (F.eq(ccfg.getName(), desc.cacheName()))
continue;
String descSchema = QueryUtils.normalizeSchemaName(desc.cacheName(), desc.cacheConfiguration().getSqlSchema());
if (!F.eq(schema, descSchema))
continue;
for (QueryEntity e : desc.schema().entities()) {
tblNames.add(e.getTableName());
for (QueryIndex idx : e.getIndexes()) idxNames.add(idx.getName());
}
}
for (QueryEntity e : ccfg.getQueryEntities()) {
if (!tblNames.add(e.getTableName()))
return new SchemaOperationException(SchemaOperationException.CODE_TABLE_EXISTS, e.getTableName());
for (QueryIndex idx : e.getIndexes()) if (!idxNames.add(idx.getName()))
return new SchemaOperationException(SchemaOperationException.CODE_INDEX_EXISTS, idx.getName());
}
return null;
}
Aggregations