Search in sources :

Example 1 with IndexDefinition

use of org.apache.ignite.internal.cache.query.index.IndexDefinition in project ignite by apache.

the class GeoSpatialUtils method createIndex.

/**
 */
public static GridH2SpatialIndex createIndex(GridH2Table tbl, String idxName, List<IndexColumn> cols) {
    try {
        IndexName name = new IndexName(tbl.cacheName(), tbl.getSchema().getName(), tbl.getName(), idxName);
        LinkedHashMap<String, IndexKeyDefinition> keyDefs = new QueryIndexKeyDefinitionProvider(tbl, cols).keyDefinitions();
        List<InlineIndexKeyType> idxKeyTypes = InlineIndexKeyTypeRegistry.types(keyDefs.values(), DUMMY_SETTINGS);
        QueryIndexRowHandler rowHnd = new QueryIndexRowHandler(tbl, cols, keyDefs, idxKeyTypes, DUMMY_SETTINGS);
        final int segments = tbl.rowDescriptor().cacheInfo().config().getQueryParallelism();
        IndexDefinition def = new GeoSpatialIndexDefinition(name, keyDefs, rowHnd, segments);
        Index idx = tbl.cacheContext().kernalContext().indexProcessor().createIndex(tbl.cacheContext(), GeoSpatialIndexFactory.INSTANCE, def);
        return new GridH2SpatialIndex(idx.unwrap(GeoSpatialIndexImpl.class));
    } catch (Exception e) {
        throw new IgniteException("Failed to instantiate", e);
    }
}
Also used : QueryIndexKeyDefinitionProvider(org.apache.ignite.internal.processors.query.h2.index.QueryIndexKeyDefinitionProvider) IndexKeyDefinition(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition) InlineIndexKeyType(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType) Index(org.apache.ignite.internal.cache.query.index.Index) QueryIndexRowHandler(org.apache.ignite.internal.processors.query.h2.index.QueryIndexRowHandler) IgniteException(org.apache.ignite.IgniteException) IndexName(org.apache.ignite.internal.cache.query.index.IndexName) IndexDefinition(org.apache.ignite.internal.cache.query.index.IndexDefinition) IgniteException(org.apache.ignite.IgniteException)

Example 2 with IndexDefinition

use of org.apache.ignite.internal.cache.query.index.IndexDefinition in project ignite by apache.

the class GridH2Table method destroyIndex.

/**
 * Destroy index with GridIndexManager.
 */
private void destroyIndex(Index idx) {
    if (idx instanceof GridH2IndexBase) {
        GridH2IndexBase h2idx = (GridH2IndexBase) idx;
        // Destroy underlying Ignite index.
        IndexDefinition deleteDef = new IndexDefinition() {

            /**
             * {@inheritDoc}
             */
            @Override
            public IndexName idxName() {
                return new IndexName(cacheName(), getSchema().getName(), tableName, idx.getName());
            }

            /**
             * {@inheritDoc}
             */
            @Override
            public LinkedHashMap<String, IndexKeyDefinition> indexKeyDefinitions() {
                throw new UnsupportedOperationException("Hasn't be invoked for destroyed index.");
            }
        };
        idxMgr.removeIndex(cacheContext(), deleteDef.idxName(), !rmIndex);
        // Call it too, if H2 index stores some state.
        h2idx.destroy(rmIndex);
    }
}
Also used : IndexName(org.apache.ignite.internal.cache.query.index.IndexName) IndexDefinition(org.apache.ignite.internal.cache.query.index.IndexDefinition) IndexKeyDefinition(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition)

Aggregations

IndexDefinition (org.apache.ignite.internal.cache.query.index.IndexDefinition)2 IndexName (org.apache.ignite.internal.cache.query.index.IndexName)2 IndexKeyDefinition (org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition)2 IgniteException (org.apache.ignite.IgniteException)1 Index (org.apache.ignite.internal.cache.query.index.Index)1 InlineIndexKeyType (org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType)1 QueryIndexKeyDefinitionProvider (org.apache.ignite.internal.processors.query.h2.index.QueryIndexKeyDefinitionProvider)1 QueryIndexRowHandler (org.apache.ignite.internal.processors.query.h2.index.QueryIndexRowHandler)1