Search in sources :

Example 1 with MergeIterator

use of com.baidu.hugegraph.backend.serializer.MergeIterator in project incubator-hugegraph by apache.

the class CassandraStore method query.

@Override
public Iterator<BackendEntry> query(Query query) {
    this.checkOpened();
    HugeType type = CassandraTable.tableType(query);
    String tableName = query.olap() ? this.olapTableName(type) : type.string();
    CassandraTable table = this.table(tableName);
    Iterator<BackendEntry> entries = table.query(this.session(), query);
    // Merge olap results as needed
    Set<Id> olapPks = query.olapPks();
    if (this.isGraphStore && !olapPks.isEmpty()) {
        List<Iterator<BackendEntry>> iterators = new ArrayList<>();
        for (Id pk : olapPks) {
            Query q = query.copy();
            table = this.table(this.olapTableName(pk));
            iterators.add(table.query(this.session(), q));
        }
        entries = new MergeIterator<>(entries, iterators, BackendEntry::mergeable);
    }
    return entries;
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) Query(com.baidu.hugegraph.backend.query.Query) Iterator(java.util.Iterator) MergeIterator(com.baidu.hugegraph.backend.serializer.MergeIterator) ArrayList(java.util.ArrayList) Id(com.baidu.hugegraph.backend.id.Id) HugeType(com.baidu.hugegraph.type.HugeType)

Example 2 with MergeIterator

use of com.baidu.hugegraph.backend.serializer.MergeIterator in project incubator-hugegraph by apache.

the class RocksDBStore method query.

@Override
public Iterator<BackendEntry> query(Query query) {
    Lock readLock = this.storeLock.readLock();
    readLock.lock();
    try {
        this.checkOpened();
        HugeType tableType = RocksDBTable.tableType(query);
        RocksDBTable table;
        RocksDBSessions.Session session;
        if (query.olap()) {
            table = this.table(this.olapTableName(tableType));
            session = this.session(HugeType.OLAP);
        } else {
            table = this.table(tableType);
            session = this.session(tableType);
        }
        Iterator<BackendEntry> entries = table.query(session, query);
        // Merge olap results as needed
        Set<Id> olapPks = query.olapPks();
        if (this.isGraphStore && !olapPks.isEmpty()) {
            List<Iterator<BackendEntry>> iterators = new ArrayList<>();
            for (Id pk : olapPks) {
                Query q = query.copy();
                table = this.table(this.olapTableName(pk));
                iterators.add(table.query(this.session(HugeType.OLAP), q));
            }
            entries = new MergeIterator<>(entries, iterators, BackendEntry::mergeable);
        }
        return entries;
    } finally {
        readLock.unlock();
    }
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) Query(com.baidu.hugegraph.backend.query.Query) ArrayList(java.util.ArrayList) HugeType(com.baidu.hugegraph.type.HugeType) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock) MergeIterator(com.baidu.hugegraph.backend.serializer.MergeIterator) Iterator(java.util.Iterator) Session(com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session) Id(com.baidu.hugegraph.backend.id.Id)

Aggregations

Id (com.baidu.hugegraph.backend.id.Id)2 Query (com.baidu.hugegraph.backend.query.Query)2 MergeIterator (com.baidu.hugegraph.backend.serializer.MergeIterator)2 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)2 HugeType (com.baidu.hugegraph.type.HugeType)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 Session (com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session)1 Lock (java.util.concurrent.locks.Lock)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1