Search in sources :

Example 46 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class DynamicIndexAbstractBasicSelfTest method checkCreateColumnWithAlias.

/**
     * Check index creation on aliased column.
     *
     * @param mode Mode.
     * @param atomicityMode Atomicity mode.
     * @param near Near flag.
     * @throws Exception If failed.
     */
private void checkCreateColumnWithAlias(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
    initialize(mode, atomicityMode, near);
    assertSchemaException(new RunnableX() {

        @Override
        public void run() throws Exception {
            QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_2_ESCAPED));
            dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false);
        }
    }, IgniteQueryErrorCode.COLUMN_NOT_FOUND);
    assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);
    QueryIndex idx = index(IDX_NAME_1, field(alias(FIELD_NAME_2_ESCAPED)));
    dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false);
    assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, field(alias(FIELD_NAME_2_ESCAPED)));
    assertSimpleIndexOperations(SQL_SIMPLE_FIELD_2);
    assertIndexUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_2, SQL_ARG_1);
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) CacheException(javax.cache.CacheException)

Example 47 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class GridQueryParsingTest method buildCreateIndex.

/**
     *
     */
private static GridSqlCreateIndex buildCreateIndex(String name, String tblName, String schemaName, boolean ifNotExists, QueryIndexType type, Object... flds) {
    QueryIndex idx = new QueryIndex();
    idx.setName(name);
    assert !F.isEmpty(flds) && flds.length % 2 == 0;
    LinkedHashMap<String, Boolean> trueFlds = new LinkedHashMap<>();
    for (int i = 0; i < flds.length / 2; i++) trueFlds.put((String) flds[i * 2], (Boolean) flds[i * 2 + 1]);
    idx.setFields(trueFlds);
    idx.setIndexType(type);
    GridSqlCreateIndex res = new GridSqlCreateIndex();
    res.schemaName(schemaName);
    res.tableName(tblName);
    res.ifNotExists(ifNotExists);
    res.index(idx);
    return res;
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) LinkedHashMap(java.util.LinkedHashMap)

Example 48 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class CacheConfiguration method convert.

/**
     * @param desc Type descriptor.
     * @return Type metadata.
     */
private static QueryEntity convert(TypeDescriptor desc) {
    QueryEntity entity = new QueryEntity();
    // Key and val types.
    entity.setKeyType(desc.keyClass().getName());
    entity.setValueType(desc.valueClass().getName());
    for (ClassProperty prop : desc.props.values()) entity.addQueryField(prop.fullName(), U.box(prop.type()).getName(), prop.alias());
    entity.setKeyFields(desc.keyProps);
    QueryIndex txtIdx = null;
    Collection<QueryIndex> idxs = new ArrayList<>();
    for (Map.Entry<String, GridQueryIndexDescriptor> idxEntry : desc.indexes().entrySet()) {
        GridQueryIndexDescriptor idx = idxEntry.getValue();
        if (idx.type() == QueryIndexType.FULLTEXT) {
            assert txtIdx == null;
            txtIdx = new QueryIndex();
            txtIdx.setIndexType(QueryIndexType.FULLTEXT);
            txtIdx.setFieldNames(idx.fields(), true);
            txtIdx.setName(idxEntry.getKey());
        } else {
            Collection<String> grp = new ArrayList<>();
            for (String fieldName : idx.fields()) grp.add(idx.descending(fieldName) ? fieldName + " desc" : fieldName);
            QueryIndex sortedIdx = new QueryIndex();
            sortedIdx.setIndexType(idx.type());
            LinkedHashMap<String, Boolean> fields = new LinkedHashMap<>();
            for (String f : idx.fields()) fields.put(f, !idx.descending(f));
            sortedIdx.setFields(fields);
            sortedIdx.setName(idxEntry.getKey());
            idxs.add(sortedIdx);
        }
    }
    if (desc.valueTextIndex()) {
        if (txtIdx == null) {
            txtIdx = new QueryIndex();
            txtIdx.setIndexType(QueryIndexType.FULLTEXT);
            txtIdx.setFieldNames(Arrays.asList(QueryUtils.VAL_FIELD_NAME), true);
        } else
            txtIdx.getFields().put(QueryUtils.VAL_FIELD_NAME, true);
    }
    if (txtIdx != null)
        idxs.add(txtIdx);
    if (!F.isEmpty(idxs))
        entity.setIndexes(idxs);
    return entity;
}
Also used : ArrayList(java.util.ArrayList) QueryEntity(org.apache.ignite.cache.QueryEntity) LinkedHashMap(java.util.LinkedHashMap) QueryIndex(org.apache.ignite.cache.QueryIndex) GridQueryIndexDescriptor(org.apache.ignite.internal.processors.query.GridQueryIndexDescriptor) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 49 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class GridCacheQuerySqlFieldInlineSizeSelfTest method testGroupIndex.

/**
 * @throws Exception If failed.
 */
public void testGroupIndex() throws Exception {
    CacheConfiguration ccfg = defaultCacheConfiguration();
    ccfg.setIndexedTypes(Integer.class, TestValueGroupIndex.class);
    assertEquals(1, ccfg.getQueryEntities().size());
    QueryEntity ent = (QueryEntity) ccfg.getQueryEntities().iterator().next();
    assertEquals(1, ent.getIndexes().size());
    QueryIndex idx = ent.getIndexes().iterator().next();
    assertEquals(10, idx.getInlineSize());
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 50 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class GridCacheQuerySqlFieldInlineSizeSelfTest method testSingleFieldIndexes.

/**
 * @throws Exception If failed.
 */
public void testSingleFieldIndexes() throws Exception {
    CacheConfiguration ccfg = defaultCacheConfiguration();
    ccfg.setIndexedTypes(Integer.class, TestValueSingleFieldIndexes.class);
    assertEquals(1, ccfg.getQueryEntities().size());
    QueryEntity ent = (QueryEntity) ccfg.getQueryEntities().iterator().next();
    assertEquals(2, ent.getIndexes().size());
    for (QueryIndex idx : ent.getIndexes()) {
        if (idx.getFields().containsKey("val0"))
            assertEquals(10, idx.getInlineSize());
        else if (idx.getFields().containsKey("val1"))
            assertEquals(20, idx.getInlineSize());
    }
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

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