Search in sources :

Example 1 with EnumerationWrapper

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());
}
Also used : EnumerationWrapper(org.apache.rya.api.utils.EnumerationWrapper) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) RyaURI(org.apache.rya.api.domain.RyaURI) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map)

Aggregations

Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 RyaStatement (org.apache.rya.api.domain.RyaStatement)1 RyaType (org.apache.rya.api.domain.RyaType)1 RyaURI (org.apache.rya.api.domain.RyaURI)1 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)1 EnumerationWrapper (org.apache.rya.api.utils.EnumerationWrapper)1