Search in sources :

Example 31 with QueryIndex

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");
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) BinaryObject(org.apache.ignite.binary.BinaryObject) QueryEntity(org.apache.ignite.cache.QueryEntity) IgniteException(org.apache.ignite.IgniteException) SQLException(java.sql.SQLException) CacheException(javax.cache.CacheException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) JdbcSQLException(org.h2.jdbc.JdbcSQLException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) LinkedHashMap(java.util.LinkedHashMap)

Example 32 with QueryIndex

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");
}
Also used : ArrayList(java.util.ArrayList) QueryEntity(org.apache.ignite.cache.QueryEntity) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) LinkedHashMap(java.util.LinkedHashMap) QueryIndex(org.apache.ignite.cache.QueryIndex) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 33 with QueryIndex

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;
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) ArrayList(java.util.ArrayList) QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) LinkedHashMap(java.util.LinkedHashMap)

Example 34 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 35 with QueryIndex

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;
}
Also used : Employee(org.apache.ignite.examples.model.Employee) EmployeeKey(org.apache.ignite.examples.model.EmployeeKey) QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

QueryIndex (org.apache.ignite.cache.QueryIndex)89 QueryEntity (org.apache.ignite.cache.QueryEntity)46 LinkedHashMap (java.util.LinkedHashMap)35 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)26 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)24 ArrayList (java.util.ArrayList)21 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)20 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)14 Ignite (org.apache.ignite.Ignite)13 CacheException (javax.cache.CacheException)10 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)10 IgniteException (org.apache.ignite.IgniteException)9 HashMap (java.util.HashMap)8 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)8 Map (java.util.Map)7 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)7 HashSet (java.util.HashSet)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 BinaryObject (org.apache.ignite.binary.BinaryObject)5 CountDownLatch (java.util.concurrent.CountDownLatch)4