Search in sources :

Example 1 with MultiKeySliceQuery

use of org.janusgraph.graphdb.query.graph.MultiKeySliceQuery in project janusgraph by JanusGraph.

the class IndexSerializer method query.

/* ################################################
                Querying
    ################################################### */
public Stream<Object> query(final JointIndexQuery.Subquery query, final BackendTransaction tx) {
    final IndexType index = query.getIndex();
    if (index.isCompositeIndex()) {
        final MultiKeySliceQuery sq = query.getCompositeQuery();
        final List<EntryList> rs = sq.execute(tx);
        final List<Object> results = new ArrayList<>(rs.get(0).size());
        for (final EntryList r : rs) {
            for (final java.util.Iterator<Entry> iterator = r.reuseIterator(); iterator.hasNext(); ) {
                final Entry entry = iterator.next();
                final ReadBuffer entryValue = entry.asReadBuffer();
                entryValue.movePositionTo(entry.getValuePosition());
                switch(index.getElement()) {
                    case VERTEX:
                        results.add(VariableLong.readPositive(entryValue));
                        break;
                    default:
                        results.add(bytebuffer2RelationId(entryValue));
                }
            }
        }
        return results.stream();
    } else {
        return tx.indexQuery(index.getBackingIndexName(), query.getMixedQuery()).map(IndexSerializer::string2ElementId);
    }
}
Also used : ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) IndexEntry(org.janusgraph.diskstorage.indexing.IndexEntry) Entry(org.janusgraph.diskstorage.Entry) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) MultiKeySliceQuery(org.janusgraph.graphdb.query.graph.MultiKeySliceQuery) ArrayList(java.util.ArrayList) EntryList(org.janusgraph.diskstorage.EntryList) MixedIndexType(org.janusgraph.graphdb.types.MixedIndexType) IndexType(org.janusgraph.graphdb.types.IndexType) CompositeIndexType(org.janusgraph.graphdb.types.CompositeIndexType)

Aggregations

ArrayList (java.util.ArrayList)1 Entry (org.janusgraph.diskstorage.Entry)1 EntryList (org.janusgraph.diskstorage.EntryList)1 ReadBuffer (org.janusgraph.diskstorage.ReadBuffer)1 IndexEntry (org.janusgraph.diskstorage.indexing.IndexEntry)1 StaticArrayEntry (org.janusgraph.diskstorage.util.StaticArrayEntry)1 MultiKeySliceQuery (org.janusgraph.graphdb.query.graph.MultiKeySliceQuery)1 CompositeIndexType (org.janusgraph.graphdb.types.CompositeIndexType)1 IndexType (org.janusgraph.graphdb.types.IndexType)1 MixedIndexType (org.janusgraph.graphdb.types.MixedIndexType)1