Search in sources :

Example 1 with GridQueryIndexDescriptor

use of org.apache.ignite.internal.processors.query.GridQueryIndexDescriptor in project ignite by apache.

the class H2TableDescriptor method createSystemIndexes.

/** {@inheritDoc} */
@Override
public ArrayList<Index> createSystemIndexes(GridH2Table tbl) {
    ArrayList<Index> idxs = new ArrayList<>();
    IndexColumn keyCol = tbl.indexColumn(KEY_COL, SortOrder.ASCENDING);
    IndexColumn affCol = tbl.getAffinityKeyColumn();
    if (affCol != null && H2Utils.equals(affCol, keyCol))
        affCol = null;
    GridH2RowDescriptor desc = tbl.rowDescriptor();
    Index hashIdx = createHashIndex(tbl, "_key_PK_hash", H2Utils.treeIndexColumns(desc, new ArrayList<IndexColumn>(2), keyCol, affCol));
    if (hashIdx != null)
        idxs.add(hashIdx);
    // Add primary key index.
    Index pkIdx = idx.createSortedIndex(schema, "_key_PK", tbl, true, H2Utils.treeIndexColumns(desc, new ArrayList<IndexColumn>(2), keyCol, affCol), -1);
    idxs.add(pkIdx);
    if (type().valueClass() == String.class) {
        try {
            luceneIdx = new GridLuceneIndex(idx.kernalContext(), schema.offheap(), tbl.cacheName(), type);
        } catch (IgniteCheckedException e1) {
            throw new IgniteException(e1);
        }
    }
    boolean affIdxFound = false;
    GridQueryIndexDescriptor textIdx = type.textIndex();
    if (textIdx != null) {
        try {
            luceneIdx = new GridLuceneIndex(idx.kernalContext(), schema.offheap(), tbl.cacheName(), type);
        } catch (IgniteCheckedException e1) {
            throw new IgniteException(e1);
        }
    }
    // Locate index where affinity column is first (if any).
    if (affCol != null) {
        for (GridQueryIndexDescriptor idxDesc : type.indexes().values()) {
            if (idxDesc.type() != QueryIndexType.SORTED)
                continue;
            String firstField = idxDesc.fields().iterator().next();
            Column col = tbl.getColumn(firstField);
            IndexColumn idxCol = tbl.indexColumn(col.getColumnId(), idxDesc.descending(firstField) ? SortOrder.DESCENDING : SortOrder.ASCENDING);
            affIdxFound |= H2Utils.equals(idxCol, affCol);
        }
    }
    // Add explicit affinity key index if nothing alike was found.
    if (affCol != null && !affIdxFound) {
        idxs.add(idx.createSortedIndex(schema, "AFFINITY_KEY", tbl, false, H2Utils.treeIndexColumns(desc, new ArrayList<IndexColumn>(2), affCol, keyCol), -1));
    }
    return idxs;
}
Also used : ArrayList(java.util.ArrayList) GridLuceneIndex(org.apache.ignite.internal.processors.query.h2.opt.GridLuceneIndex) GridLuceneIndex(org.apache.ignite.internal.processors.query.h2.opt.GridLuceneIndex) H2PkHashIndex(org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex) Index(org.h2.index.Index) IndexColumn(org.h2.table.IndexColumn) GridH2RowDescriptor(org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Column(org.h2.table.Column) IndexColumn(org.h2.table.IndexColumn) IgniteException(org.apache.ignite.IgniteException) GridQueryIndexDescriptor(org.apache.ignite.internal.processors.query.GridQueryIndexDescriptor)

Example 2 with GridQueryIndexDescriptor

use of org.apache.ignite.internal.processors.query.GridQueryIndexDescriptor in project ignite by apache.

the class H2TableDescriptor method createUserIndexes.

/**
     * Get collection of user indexes.
     *
     * @return User indexes.
     */
public Collection<GridH2IndexBase> createUserIndexes() {
    assert tbl != null;
    ArrayList<GridH2IndexBase> res = new ArrayList<>();
    for (GridQueryIndexDescriptor idxDesc : type.indexes().values()) {
        GridH2IndexBase idx = createUserIndex(idxDesc);
        res.add(idx);
    }
    return res;
}
Also used : GridH2IndexBase(org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase) ArrayList(java.util.ArrayList) GridQueryIndexDescriptor(org.apache.ignite.internal.processors.query.GridQueryIndexDescriptor)

Example 3 with GridQueryIndexDescriptor

use of org.apache.ignite.internal.processors.query.GridQueryIndexDescriptor 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)

Aggregations

ArrayList (java.util.ArrayList)3 GridQueryIndexDescriptor (org.apache.ignite.internal.processors.query.GridQueryIndexDescriptor)3 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 QueryEntity (org.apache.ignite.cache.QueryEntity)1 QueryIndex (org.apache.ignite.cache.QueryIndex)1 H2PkHashIndex (org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex)1 GridH2IndexBase (org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase)1 GridH2RowDescriptor (org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor)1 GridLuceneIndex (org.apache.ignite.internal.processors.query.h2.opt.GridLuceneIndex)1 Index (org.h2.index.Index)1 Column (org.h2.table.Column)1 IndexColumn (org.h2.table.IndexColumn)1