use of org.apache.geode.internal.cache.persistence.query.CloseableIterator in project geode by apache.
the class HashIndex method queryEquijoinCondition.
/**
* computes the resultset of an equijoin query
*/
public List queryEquijoinCondition(IndexProtocol indx, ExecutionContext context) throws TypeMismatchException, FunctionDomainException, NameResolutionException, QueryInvocationTargetException {
// get a read lock when doing a lookup
long start = updateIndexUseStats();
((AbstractIndex) indx).updateIndexUseStats();
List data = new ArrayList();
Iterator inner = null;
try {
// We will iterate over each of the valueToEntries Map to obtain the keys
Iterator outer = entriesSet.iterator();
if (indx instanceof CompactRangeIndex) {
inner = ((CompactRangeIndex) indx).getIndexStorage().iterator(null);
} else {
inner = ((RangeIndex) indx).getValueToEntriesMap().entrySet().iterator();
}
Map.Entry outerEntry = null;
Object innerEntry = null;
Object outerKey = null;
Object innerKey = null;
// boolean incrementOuter = true;
boolean incrementInner = true;
outer: while (outer.hasNext()) {
// if (incrementOuter) {
outerEntry = (Map.Entry) outer.next();
// }
outerKey = outerEntry.getKey();
// TODO: eliminate use of labels
inner: while (!incrementInner || inner.hasNext()) {
if (incrementInner) {
innerEntry = inner.next();
if (innerEntry instanceof IndexStoreEntry) {
innerKey = ((IndexStoreEntry) innerEntry).getDeserializedKey();
} else {
innerKey = ((Map.Entry) innerEntry).getKey();
}
}
int compare = ((Comparable) outerKey).compareTo(innerKey);
if (compare == 0) {
Object innerValue = null;
if (innerEntry instanceof IndexStoreEntry) {
innerValue = ((CompactRangeIndex) indx).getIndexStorage().get(outerKey);
} else {
innerValue = ((Map.Entry) innerEntry).getValue();
}
populateListForEquiJoin(data, outerEntry.getValue(), innerValue, context, innerKey);
incrementInner = true;
continue outer;
} else if (compare < 0) {
// Asif :The outer key is smaller than the inner key. That means
// that we need
// to increment the outer loop without moving inner loop.
// incrementOuter = true;
incrementInner = false;
continue outer;
} else {
// The outer key is greater than inner key , so increment the
// inner loop without changing outer
incrementInner = true;
}
}
break;
}
return data;
} finally {
((AbstractIndex) indx).updateIndexUseEndStats(start);
updateIndexUseEndStats(start);
if (inner != null && indx instanceof CompactRangeIndex) {
((CloseableIterator<IndexStoreEntry>) inner).close();
}
}
}
Aggregations