use of org.apache.rya.api.utils.EnumerationWrapper in project incubator-rya by apache.
the class HashJoin method join.
@Override
public CloseableIteration<RyaURI, RyaDAOException> join(C conf, Map.Entry<RyaURI, RyaType>... predObjs) throws RyaDAOException {
ConcurrentHashMap<RyaURI, Integer> ht = new ConcurrentHashMap<RyaURI, Integer>();
int count = 0;
boolean first = true;
for (Map.Entry<RyaURI, RyaType> predObj : predObjs) {
count++;
RyaURI pred = predObj.getKey();
RyaType obj = predObj.getValue();
// query
CloseableIteration<RyaStatement, RyaDAOException> results = ryaQueryEngine.query(new RyaStatement(null, pred, obj), null);
// add to hashtable
while (results.hasNext()) {
RyaURI subject = results.next().getSubject();
if (!first) {
if (!ht.containsKey(subject)) {
// not in join
continue;
}
}
ht.put(subject, count);
}
// remove from hashtable values that are under count
if (first) {
first = false;
} else {
for (Map.Entry<RyaURI, Integer> entry : ht.entrySet()) {
if (entry.getValue() < count) {
ht.remove(entry.getKey());
}
}
}
}
return new EnumerationWrapper<RyaURI, RyaDAOException>(ht.keys());
}
Aggregations