Search in sources :

Example 31 with GridH2Table

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2Table in project ignite by apache.

the class GridH2ProxyIndex method createLookupBatch.

/**
 * {@inheritDoc}
 */
@Override
public IndexLookupBatch createLookupBatch(TableFilter[] filters, int filter) {
    IndexLookupBatch batch = idx.createLookupBatch(filters, filter);
    if (batch == null)
        return null;
    GridH2RowDescriptor rowDesc = ((GridH2Table) idx.getTable()).rowDescriptor();
    return new ProxyDistributedLookupBatch(batch, rowDesc);
}
Also used : ProxyDistributedLookupBatch(org.apache.ignite.internal.processors.query.h2.opt.join.ProxyDistributedLookupBatch) IndexLookupBatch(org.h2.index.IndexLookupBatch)

Example 32 with GridH2Table

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2Table 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 33 with GridH2Table

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2Table in project ignite by apache.

the class H2DynamicTableSelfTest method assertAffinityCacheConfiguration.

/**
 * Check that dynamic cache created with {@code CREATE TABLE} is correctly configured affinity wise.
 * @param cacheName Cache name to check.
 * @param affKeyFieldName Expected affinity key field name.
 */
private void assertAffinityCacheConfiguration(String cacheName, String affKeyFieldName) {
    String actualCacheName = cacheName(cacheName);
    Collection<GridQueryTypeDescriptor> types = client().context().query().types(actualCacheName);
    assertEquals(1, types.size());
    GridQueryTypeDescriptor type = types.iterator().next();
    assertTrue(type.name().startsWith(actualCacheName));
    assertEquals(cacheName, type.tableName());
    assertEquals(affKeyFieldName, type.affinityKey());
    GridH2Table tbl = ((IgniteH2Indexing) queryProcessor(client()).getIndexing()).schemaManager().dataTable("PUBLIC", cacheName);
    assertNotNull(tbl);
    assertNotNull(tbl.getAffinityKeyColumn());
    assertEquals(affKeyFieldName, tbl.getAffinityKeyColumn().columnName);
}
Also used : GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) GridQueryTypeDescriptor(org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor)

Example 34 with GridH2Table

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2Table in project ignite by apache.

the class IgniteH2Indexing method indexSize.

/**
 * {@inheritDoc}
 */
@Override
public long indexSize(String schemaName, String tblName, String idxName) throws IgniteCheckedException {
    GridH2Table tbl = schemaMgr.dataTable(schemaName, tblName);
    if (tbl == null)
        return 0;
    H2TreeIndex idx = (H2TreeIndex) tbl.userIndex(idxName);
    return idx == null ? 0 : idx.size();
}
Also used : H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)

Example 35 with GridH2Table

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2Table in project ignite by apache.

the class IgniteH2Indexing method createSortedIndex.

/**
 * Create sorted index.
 *
 * @param name Index name,
 * @param tbl Table.
 * @param pk Primary key flag.
 * @param affinityKey Affinity key flag.
 * @param unwrappedCols Unwrapped index columns for complex types.
 * @param wrappedCols Index columns as is complex types.
 * @param inlineSize Index inline size.
 * @param cacheVisitor whether index created with new cache or on existing one.
 * @return Index.
 */
@SuppressWarnings("ConstantConditions")
GridH2IndexBase createSortedIndex(String name, GridH2Table tbl, boolean pk, boolean affinityKey, List<IndexColumn> unwrappedCols, List<IndexColumn> wrappedCols, int inlineSize, @Nullable SchemaIndexCacheVisitor cacheVisitor) {
    GridCacheContextInfo cacheInfo = tbl.cacheInfo();
    if (log.isDebugEnabled())
        log.debug("Creating cache index [cacheId=" + cacheInfo.cacheId() + ", idxName=" + name + ']');
    if (cacheInfo.affinityNode()) {
        QueryIndexDefinition idxDef = new QueryIndexDefinition(tbl, name, ctx.indexProcessor().rowCacheCleaner(cacheInfo.groupId()), pk, affinityKey, unwrappedCols, wrappedCols, inlineSize);
        org.apache.ignite.internal.cache.query.index.Index index;
        if (cacheVisitor != null)
            index = ctx.indexProcessor().createIndexDynamically(tbl.cacheContext(), idxFactory, idxDef, cacheVisitor);
        else
            index = ctx.indexProcessor().createIndex(tbl.cacheContext(), idxFactory, idxDef);
        InlineIndexImpl queryIndex = index.unwrap(InlineIndexImpl.class);
        return new H2TreeIndex(queryIndex, tbl, unwrappedCols.toArray(new IndexColumn[0]), pk, log);
    } else {
        ClientIndexDefinition d = new ClientIndexDefinition(tbl, new IndexName(tbl.cacheName(), tbl.getSchema().getName(), tbl.getName(), name), unwrappedCols, inlineSize, tbl.cacheInfo().config().getSqlIndexMaxInlineSize());
        org.apache.ignite.internal.cache.query.index.Index index = ctx.indexProcessor().createIndex(tbl.cacheContext(), ClientIndexFactory.INSTANCE, d);
        InlineIndex idx = index.unwrap(InlineIndex.class);
        IndexType idxType = pk ? IndexType.createPrimaryKey(false, false) : IndexType.createNonUnique(false, false, false);
        return new H2TreeClientIndex(idx, tbl, name, unwrappedCols.toArray(new IndexColumn[0]), idxType);
    }
}
Also used : H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex) InlineIndex(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndex) IndexColumn(org.h2.table.IndexColumn) IndexName(org.apache.ignite.internal.cache.query.index.IndexName) InlineIndexImpl(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl) QueryIndexDefinition(org.apache.ignite.internal.processors.query.h2.index.QueryIndexDefinition) GridCacheContextInfo(org.apache.ignite.internal.processors.cache.GridCacheContextInfo) H2TreeClientIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeClientIndex) ClientIndexDefinition(org.apache.ignite.internal.processors.query.h2.index.client.ClientIndexDefinition) IndexType(org.h2.index.IndexType)

Aggregations

GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)66 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)26 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)26 GridH2RowDescriptor (org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor)18 GridSqlColumn (org.apache.ignite.internal.processors.query.h2.sql.GridSqlColumn)18 Column (org.h2.table.Column)18 ArrayList (java.util.ArrayList)16 IgniteException (org.apache.ignite.IgniteException)15 HashSet (java.util.HashSet)13 GridSqlElement (org.apache.ignite.internal.processors.query.h2.sql.GridSqlElement)12 GridQueryTypeDescriptor (org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor)11 GridSqlTable (org.apache.ignite.internal.processors.query.h2.sql.GridSqlTable)11 SQLException (java.sql.SQLException)10 List (java.util.List)10 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)10 GridSqlSelect (org.apache.ignite.internal.processors.query.h2.sql.GridSqlSelect)8 Map (java.util.Map)7 IgniteEx (org.apache.ignite.internal.IgniteEx)7 GridQueryProperty (org.apache.ignite.internal.processors.query.GridQueryProperty)7 HashMap (java.util.HashMap)5