Search in sources :

Example 11 with IndexRow

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

the class InlineIndexImpl method findFirst.

/**
 * {@inheritDoc}
 */
@Override
public GridCursor<IndexRow> findFirst(int segment, IndexQueryContext qryCtx) throws IgniteCheckedException {
    InlineTreeFilterClosure closure = filterClosure(qryCtx);
    IndexRow found = segments[segment].findFirst(closure);
    if (found == null || isExpired(found))
        return IndexValueCursor.EMPTY;
    return new SingleCursor<>(found);
}
Also used : SingleCursor(org.apache.ignite.internal.cache.query.index.SingleCursor) IndexRow(org.apache.ignite.internal.cache.query.index.sorted.IndexRow)

Example 12 with IndexRow

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

the class GeoSpatialIndexImpl method remove.

/**
 */
private boolean remove(CacheDataRow row) {
    checkClosed();
    Object key = def.rowHandler().key(row);
    assert key != null;
    Long rowId = keyToId.remove(key);
    assert rowId != null;
    IndexRow oldRow = idToRow.remove(rowId);
    assert oldRow != null;
    final int seg = segmentForRow(row);
    if (!segments[seg].remove(getEnvelope(row, rowId), rowId))
        throw DbException.throwInternalError("row not found");
    rowCnt--;
    return oldRow != null;
}
Also used : IndexRow(org.apache.ignite.internal.cache.query.index.sorted.IndexRow)

Example 13 with IndexRow

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

the class GeoSpatialIndexImpl method rowIterator.

/**
 * @param i Spatial key iterator.
 * @param filter Table filter.
 * @return Iterator over rows.
 */
@SuppressWarnings("unchecked")
private GridCursor<IndexRow> rowIterator(Iterator<SpatialKey> i, TableFilter filter) {
    if (!i.hasNext())
        return IndexValueCursor.EMPTY;
    long time = System.currentTimeMillis();
    IndexingQueryFilter qryFilter = null;
    QueryContext qctx = H2Utils.context(filter.getSession());
    if (qctx != null)
        qryFilter = qctx.filter();
    IndexingQueryCacheFilter qryCacheFilter = qryFilter != null ? qryFilter.forCache(def.rowHandler().getTable().cacheName()) : null;
    List<IndexRow> rows = new ArrayList<>();
    do {
        IndexRow row = idToRow.get(i.next().getId());
        CacheDataRow cacheRow = row.cacheDataRow();
        assert row != null;
        if (cacheRow.expireTime() != 0 && cacheRow.expireTime() <= time)
            continue;
        if (qryCacheFilter == null || qryCacheFilter.applyPartition(cacheRow.partition()))
            rows.add(row);
    } while (i.hasNext());
    return new GridCursorIteratorWrapper(rows.iterator());
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) IndexingQueryFilter(org.apache.ignite.spi.indexing.IndexingQueryFilter) IndexRow(org.apache.ignite.internal.cache.query.index.sorted.IndexRow) ArrayList(java.util.ArrayList) GridCursorIteratorWrapper(org.apache.ignite.internal.util.GridCursorIteratorWrapper) IndexingQueryCacheFilter(org.apache.ignite.spi.indexing.IndexingQueryCacheFilter)

Example 14 with IndexRow

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

the class GeoSpatialIndexImpl method findFirstOrLast.

/**
 * {@inheritDoc}
 */
@Override
public GridCursor<IndexRow> findFirstOrLast(int seg, boolean first) {
    Lock l = lock.readLock();
    l.lock();
    try {
        checkClosed();
        if (!first)
            throw DbException.throwInternalError("Spatial Index can only be fetch by ascending order");
        final MVRTreeMap<Long> segment = segments[seg];
        GridCursor<IndexRow> iter = rowIterator(segment.keySet().iterator(), null);
        return new SingleCursor<>(iter.next() ? iter.get() : null);
    } catch (IgniteCheckedException e) {
        throw DbException.convert(e);
    } finally {
        l.unlock();
    }
}
Also used : SingleCursor(org.apache.ignite.internal.cache.query.index.SingleCursor) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IndexRow(org.apache.ignite.internal.cache.query.index.sorted.IndexRow) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Example 15 with IndexRow

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

the class GridH2SpatialIndex method findByGeometry.

/**
 * {@inheritDoc}
 */
@Override
public Cursor findByGeometry(TableFilter filter, SearchRow first, SearchRow last, SearchRow intersection) {
    Value v = intersection.getValue(columnIds[0]);
    Geometry g = ((ValueGeometry) v.convertTo(Value.GEOMETRY)).getGeometry();
    int seg = segmentsCount() == 1 ? 0 : H2Utils.context(filter.getSession()).segment();
    GridCursor<IndexRow> cursor = delegate.findByGeometry(seg, filter, g);
    GridCursor<H2Row> h2cursor = new IndexValueCursor<>(cursor, this::mapIndexRow);
    return new H2Cursor(h2cursor);
}
Also used : ValueGeometry(org.h2.value.ValueGeometry) Geometry(org.locationtech.jts.geom.Geometry) ValueGeometry(org.h2.value.ValueGeometry) IndexRow(org.apache.ignite.internal.cache.query.index.sorted.IndexRow) H2Cursor(org.apache.ignite.internal.processors.query.h2.H2Cursor) Value(org.h2.value.Value) IndexValueCursor(org.apache.ignite.internal.cache.query.index.sorted.IndexValueCursor)

Aggregations

IndexRow (org.apache.ignite.internal.cache.query.index.sorted.IndexRow)17 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 H2Cursor (org.apache.ignite.internal.processors.query.h2.H2Cursor)4 SingleCursor (org.apache.ignite.internal.cache.query.index.SingleCursor)3 IndexKeyDefinition (org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition)3 IndexValueCursor (org.apache.ignite.internal.cache.query.index.sorted.IndexValueCursor)3 SortedIndexDefinition (org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition)3 IndexQueryContext (org.apache.ignite.internal.cache.query.index.sorted.inline.IndexQueryContext)3 FailureContext (org.apache.ignite.failure.FailureContext)2 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)2 H2Row (org.apache.ignite.internal.processors.query.h2.opt.H2Row)2 QueryContext (org.apache.ignite.internal.processors.query.h2.opt.QueryContext)2 ArrayList (java.util.ArrayList)1 NoSuchElementException (java.util.NoSuchElementException)1 Lock (java.util.concurrent.locks.Lock)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 IgniteException (org.apache.ignite.IgniteException)1 IndexKeyTypeSettings (org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings)1 IndexRowImpl (org.apache.ignite.internal.cache.query.index.sorted.IndexRowImpl)1