use of org.apache.ignite.cache.QueryIndex in project ignite by apache.
the class H2DynamicTableSelfTest method testIndexNameConflictCheckDiscovery.
/**
* Tests index name conflict check in discovery thread.
* @throws Exception if failed.
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void testIndexNameConflictCheckDiscovery() throws Exception {
execute(grid(0), "CREATE TABLE \"Person\" (id int primary key, name varchar)");
execute(grid(0), "CREATE INDEX \"idx\" ON \"Person\" (\"name\")");
GridTestUtils.assertThrows(null, new Callable<Object>() {
@Override
public Object call() throws Exception {
QueryEntity e = new QueryEntity();
e.setTableName("City");
e.setKeyFields(Collections.singleton("name"));
e.setFields(new LinkedHashMap<>(Collections.singletonMap("name", String.class.getName())));
e.setIndexes(Collections.singleton(new QueryIndex("name").setName("idx")));
e.setKeyType("CityKey");
e.setValueType("City");
queryProcessor(client()).dynamicTableCreate("PUBLIC", e, CacheMode.PARTITIONED.name(), null, null, null, null, CacheAtomicityMode.ATOMIC, null, 10, false);
return null;
}
}, SchemaOperationException.class, "Index already exists: idx");
}
use of org.apache.ignite.cache.QueryIndex in project ignite by apache.
the class QueryEntityValidationSelfTest method testIndexTypeNull.
/**
* Test failure if index type is null.
*
* @throws Exception If failed.
*/
public void testIndexTypeNull() 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());
entity.setFields(fields);
LinkedHashMap<String, Boolean> idxFields = new LinkedHashMap<>();
idxFields.put("a", true);
QueryIndex idx = new QueryIndex().setName("idx").setFields(idxFields).setIndexType(null);
List<QueryIndex> idxs = new ArrayList<>();
idxs.add(idx);
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, "Index type is not set");
}
use of org.apache.ignite.cache.QueryIndex in project ignite by apache.
the class IgniteDbSingleNodeWithIndexingWalRestoreTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(gridName);
BinaryConfiguration binCfg = new BinaryConfiguration();
binCfg.setCompactFooter(true);
cfg.setBinaryConfiguration(binCfg);
CacheConfiguration indexedCacheCfg = new CacheConfiguration();
indexedCacheCfg.setName("indexedCache");
List<QueryEntity> qryEntities = new ArrayList<>();
{
QueryEntity qryEntity = new QueryEntity();
qryEntity.setKeyType(Integer.class.getName());
qryEntity.setValueType(BINARY_TYPE_NAME);
LinkedHashMap<String, String> fields = new LinkedHashMap<>();
fields.put(BINARY_TYPE_FIELD_NAME, String.class.getName());
qryEntity.setFields(fields);
qryEntity.setIndexes(F.asList(new QueryIndex(BINARY_TYPE_FIELD_NAME)));
qryEntities.add(qryEntity);
}
{
QueryEntity qryEntity = new QueryEntity();
qryEntity.setKeyType(Integer.class.getName());
qryEntity.setValueType(RegularPerson.class.getName());
LinkedHashMap<String, String> fields = new LinkedHashMap<>();
fields.put("regName", String.class.getName());
qryEntity.setFields(fields);
qryEntity.setIndexes(F.asList(new QueryIndex("regName")));
qryEntities.add(qryEntity);
}
indexedCacheCfg.setQueryEntities(qryEntities);
cfg.setCacheConfiguration(indexedCacheCfg);
DataStorageConfiguration memCfg = new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setMaxSize(100 * 1024 * 1024).setPersistenceEnabled(true)).setWalMode(WALMode.LOG_ONLY);
cfg.setDataStorageConfiguration(memCfg);
cfg.setConsistentId(gridName);
return cfg;
}
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 CacheClientBinaryQueryExample method createEmployeeQueryEntity.
/**
* Create cache type metadata for {@link Employee}.
*
* @return Cache type metadata.
*/
private static QueryEntity createEmployeeQueryEntity() {
QueryEntity employeeEntity = new QueryEntity();
employeeEntity.setValueType(Employee.class.getName());
employeeEntity.setKeyType(EmployeeKey.class.getName());
LinkedHashMap<String, String> fields = new LinkedHashMap<>();
fields.put("name", String.class.getName());
fields.put("salary", Long.class.getName());
fields.put("addr.zip", Integer.class.getName());
fields.put("organizationId", Integer.class.getName());
fields.put("addr.street", Integer.class.getName());
employeeEntity.setFields(fields);
employeeEntity.setIndexes(Arrays.asList(new QueryIndex("name"), new QueryIndex("salary"), new QueryIndex("addr.zip"), new QueryIndex("organizationId"), new QueryIndex("addr.street", QueryIndexType.FULLTEXT)));
return employeeEntity;
}
Aggregations