Search in sources :

Example 6 with RangeIndexQueryCriterion

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

the class IndexQueryProcessor method prepareQuery.

/**
 * Prepare index query.
 *
 * @return Prepared query for index range.
 */
private IndexRangeQuery prepareQuery(SortedSegmentedIndex idx, IndexQueryDesc idxQryDesc) throws IgniteCheckedException {
    SortedIndexDefinition idxDef = (SortedIndexDefinition) idxProc.indexDefinition(idx.id());
    // For PK indexes will serialize _KEY column.
    if (F.isEmpty(idxQryDesc.criteria()))
        return new IndexRangeQuery(1);
    InlineIndexImpl sortedIdx = (InlineIndexImpl) idx;
    Map<String, RangeIndexQueryCriterion> merged = mergeIndexQueryCriteria(sortedIdx, idxDef, idxQryDesc);
    return alignCriteriaWithIndex(sortedIdx, merged, idxDef);
}
Also used : InlineIndexImpl(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl) SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) RangeIndexQueryCriterion(org.apache.ignite.internal.cache.query.RangeIndexQueryCriterion)

Example 7 with RangeIndexQueryCriterion

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

the class IndexQueryProcessor method alignCriteriaWithIndex.

/**
 * Checks that specified index matches index query criteria.
 */
private IndexRangeQuery alignCriteriaWithIndex(InlineIndexImpl idx, Map<String, RangeIndexQueryCriterion> criteria, IndexDefinition idxDef) {
    // Size of bounds array has to be equal to count of indexed fields.
    IndexKey[] lowerBounds = new IndexKey[idxDef.indexKeyDefinitions().size()];
    IndexKey[] upperBounds = new IndexKey[idxDef.indexKeyDefinitions().size()];
    boolean lowerAllNulls = true;
    boolean upperAllNulls = true;
    IndexRangeQuery qry = new IndexRangeQuery(criteria.size());
    // Checks that users criteria matches a prefix subset of index fields.
    int i = 0;
    for (Map.Entry<String, IndexKeyDefinition> keyDef : idxDef.indexKeyDefinitions().entrySet()) {
        RangeIndexQueryCriterion criterion = criteria.remove(keyDef.getKey());
        if (keyDef.getValue().order().sortOrder() == DESC)
            criterion = criterion.swap();
        qry.criteria[i] = criterion;
        IndexKey l = (IndexKey) criterion.lower();
        IndexKey u = (IndexKey) criterion.upper();
        if (l != null)
            lowerAllNulls = false;
        if (u != null)
            upperAllNulls = false;
        lowerBounds[i] = l;
        upperBounds[i++] = u;
        if (criteria.isEmpty())
            break;
    }
    InlineIndexRowHandler hnd = idx.segment(0).rowHandler();
    qry.lower = lowerAllNulls ? null : new IndexSearchRowImpl(lowerBounds, hnd);
    qry.upper = upperAllNulls ? null : new IndexSearchRowImpl(upperBounds, hnd);
    return qry;
}
Also used : IndexSearchRowImpl(org.apache.ignite.internal.cache.query.index.sorted.IndexSearchRowImpl) IndexKey(org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey) IndexKeyDefinition(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition) InlineIndexRowHandler(org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler) RangeIndexQueryCriterion(org.apache.ignite.internal.cache.query.RangeIndexQueryCriterion) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with RangeIndexQueryCriterion

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

the class IndexQueryCriteriaBuilder method between.

/**
 * Between.
 *
 * @param field Index field to apply criterion.
 * @param lower Inclusive lower bound.
 * @param upper Inclusive upper bound.
 * @return Criterion.
 */
public static IndexQueryCriterion between(String field, Object lower, Object upper) {
    A.notNullOrEmpty(field, "field");
    RangeIndexQueryCriterion c = new RangeIndexQueryCriterion(field, lower, upper);
    c.lowerIncl(true);
    c.upperIncl(true);
    c.lowerNull(lower == null);
    c.upperNull(upper == null);
    return c;
}
Also used : RangeIndexQueryCriterion(org.apache.ignite.internal.cache.query.RangeIndexQueryCriterion)

Example 9 with RangeIndexQueryCriterion

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

the class IndexQueryCriteriaBuilder method lt.

/**
 * Less Then.
 *
 * @param field Index field to apply criterion.
 * @param val Exclusive upper bound.
 * @return Criterion.
 */
public static IndexQueryCriterion lt(String field, Object val) {
    A.notNullOrEmpty(field, "field");
    RangeIndexQueryCriterion c = new RangeIndexQueryCriterion(field, null, val);
    c.lowerIncl(true);
    c.upperNull(val == null);
    return c;
}
Also used : RangeIndexQueryCriterion(org.apache.ignite.internal.cache.query.RangeIndexQueryCriterion)

Example 10 with RangeIndexQueryCriterion

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

the class IndexQueryCriteriaBuilder method gte.

/**
 * Greater Then or Equal To.
 *
 * @param field Index field to apply criterion.
 * @param val Inclusive lower bound.
 * @return Criterion.
 */
public static IndexQueryCriterion gte(String field, Object val) {
    A.notNullOrEmpty(field, "field");
    RangeIndexQueryCriterion c = new RangeIndexQueryCriterion(field, val, null);
    c.lowerIncl(true);
    c.upperIncl(true);
    c.lowerNull(val == null);
    return c;
}
Also used : RangeIndexQueryCriterion(org.apache.ignite.internal.cache.query.RangeIndexQueryCriterion)

Aggregations

RangeIndexQueryCriterion (org.apache.ignite.internal.cache.query.RangeIndexQueryCriterion)10 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 IndexKeyDefinition (org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition)2 IndexKey (org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Random (java.util.Random)1 IndexQueryCriterion (org.apache.ignite.cache.query.IndexQueryCriterion)1 IndexKeyTypeSettings (org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings)1 IndexRowComparator (org.apache.ignite.internal.cache.query.index.sorted.IndexRowComparator)1 IndexSearchRowImpl (org.apache.ignite.internal.cache.query.index.sorted.IndexSearchRowImpl)1 InlineIndexRowHandler (org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler)1 SortedIndexDefinition (org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition)1 InlineIndexImpl (org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl)1 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)1 CacheObjectContext (org.apache.ignite.internal.processors.cache.CacheObjectContext)1 T2 (org.apache.ignite.internal.util.typedef.T2)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 Test (org.junit.Test)1