use of org.apache.ignite.internal.cache.query.index.sorted.SortedSegmentedIndex in project ignite by apache.
the class IndexQueryProcessor method queryLocal.
/**
* Run query on local node.
*
* @return Query result that contains data iterator and related metadata.
*/
public <K, V> IndexQueryResult<K, V> queryLocal(GridCacheContext<K, V> cctx, IndexQueryDesc idxQryDesc, @Nullable IgniteBiPredicate<K, V> filter, IndexingQueryFilter cacheFilter, boolean keepBinary) throws IgniteCheckedException {
SortedSegmentedIndex idx = findSortedIndex(cctx, idxQryDesc);
IndexRangeQuery qry = prepareQuery(idx, idxQryDesc);
GridCursor<IndexRow> cursor = querySortedIndex(cctx, idx, cacheFilter, qry);
SortedIndexDefinition def = (SortedIndexDefinition) idxProc.indexDefinition(idx.id());
IndexQueryResultMeta meta = new IndexQueryResultMeta(def, qry.criteria.length);
// Map IndexRow to Cache Key-Value pair.
return new IndexQueryResult<>(meta, new GridCloseableIteratorAdapter<IgniteBiTuple<K, V>>() {
private IgniteBiTuple<K, V> currVal;
private final CacheObjectContext coctx = cctx.cacheObjectContext();
/**
* {@inheritDoc}
*/
@Override
protected boolean onHasNext() throws IgniteCheckedException {
if (currVal != null)
return true;
while (currVal == null && cursor.next()) {
IndexRow r = cursor.get();
K k = unwrap(r.cacheDataRow().key(), true);
V v = unwrap(r.cacheDataRow().value(), true);
if (filter != null) {
K k0 = keepBinary ? k : unwrap(r.cacheDataRow().key(), false);
V v0 = keepBinary ? v : unwrap(r.cacheDataRow().value(), false);
if (!filter.apply(k0, v0))
continue;
}
currVal = new IgniteBiTuple<>(k, v);
}
return currVal != null;
}
/**
* {@inheritDoc}
*/
@Override
protected IgniteBiTuple<K, V> onNext() {
if (currVal == null)
if (!hasNext())
throw new NoSuchElementException();
IgniteBiTuple<K, V> row = currVal;
currVal = null;
return row;
}
/**
*/
private <T> T unwrap(CacheObject o, boolean keepBinary) {
return (T) CacheObjectUtils.unwrapBinaryIfNeeded(coctx, o, keepBinary, false);
}
});
}
use of org.apache.ignite.internal.cache.query.index.sorted.SortedSegmentedIndex in project ignite by apache.
the class IndexQueryProcessor method indexByName.
/**
* @return Sorted index found by name.
* @throws IgniteCheckedException If index not found or specified index doesn't match query criteria.
*/
private SortedSegmentedIndex indexByName(IndexName idxName, IndexQueryDesc idxQryDesc, final Map<String, String> criteriaFlds) throws IgniteCheckedException {
SortedSegmentedIndex idx = assertSortedIndex(idxProc.index(idxName), idxQryDesc);
if (idx == null && !QueryUtils.PRIMARY_KEY_INDEX.equals(idxName.idxName())) {
String normIdxName = QueryUtils.normalizeObjectName(idxName.idxName(), false);
idxName = new IndexName(idxName.cacheName(), idxName.schemaName(), idxName.tableName(), normIdxName);
idx = assertSortedIndex(idxProc.index(idxName), idxQryDesc);
}
if (idx == null)
throw failIndexQuery("No index found for name: " + idxName.idxName(), null, idxQryDesc);
if (!checkIndex(idx, idxName.tableName(), criteriaFlds))
throw failIndexQuery("Index doesn't match criteria", null, idxQryDesc);
return idx;
}
Aggregations