Search in sources :

Example 76 with QueryIndex

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

Example 77 with QueryIndex

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");
}
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 78 with QueryIndex

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)));
}
Also used : IgniteException(org.apache.ignite.IgniteException) IgniteEx(org.apache.ignite.internal.IgniteEx) QueryIndex(org.apache.ignite.cache.QueryIndex) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteException(org.apache.ignite.IgniteException)

Example 79 with QueryIndex

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;
}
Also used : QueryEntityEx(org.apache.ignite.internal.processors.query.QueryEntityEx) ConnectorConfiguration(org.apache.ignite.configuration.ConnectorConfiguration) QueryEntity(org.apache.ignite.cache.QueryEntity) LinkedHashMap(java.util.LinkedHashMap) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) QueryIndex(org.apache.ignite.cache.QueryIndex) AffinityKey(org.apache.ignite.cache.affinity.AffinityKey) HashSet(java.util.HashSet) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 80 with QueryIndex

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;
}
Also used : SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) HashSet(java.util.HashSet)

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