Search in sources :

Example 1 with IndexSearchRowImpl

use of org.apache.ignite.internal.cache.query.index.sorted.IndexSearchRowImpl 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 2 with IndexSearchRowImpl

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

the class H2TreeIndex method preparePlainIndexKey.

/**
 */
private IndexRow preparePlainIndexKey(SearchRow row, InlineIndexRowHandler rowHnd) {
    int idxColsLen = indexColumns.length;
    IndexKey[] keys = row == null ? null : new IndexKey[idxColsLen];
    for (int i = 0; i < idxColsLen; ++i) {
        int colId = indexColumns[i].column.getColumnId();
        Value v = row.getValue(colId);
        keys[i] = v == null ? null : IndexKeyFactory.wrap(v.getObject(), v.getType(), cctx.cacheObjectContext(), queryIndex.keyTypeSettings());
    }
    return new IndexSearchRowImpl(keys, rowHnd);
}
Also used : IndexSearchRowImpl(org.apache.ignite.internal.cache.query.index.sorted.IndexSearchRowImpl) IndexKey(org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey) Value(org.h2.value.Value)

Aggregations

IndexSearchRowImpl (org.apache.ignite.internal.cache.query.index.sorted.IndexSearchRowImpl)2 IndexKey (org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 RangeIndexQueryCriterion (org.apache.ignite.internal.cache.query.RangeIndexQueryCriterion)1 IndexKeyDefinition (org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition)1 InlineIndexRowHandler (org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler)1 Value (org.h2.value.Value)1