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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations