Search in sources :

Example 1 with LongObjectOpenHashMap

use of com.carrotsearch.hppc.LongObjectOpenHashMap in project titan by thinkaurelius.

the class EdgeSerializer method parseRelation.

private RelationCache parseRelation(long vertexid, Entry data, boolean parseHeaderOnly, StandardTitanTx tx) {
    assert vertexid > 0;
    ReadBuffer column = data.getReadColumn();
    ReadBuffer value = data.getReadValue();
    LongObjectOpenHashMap properties = parseHeaderOnly ? null : new LongObjectOpenHashMap(4);
    long[] typeAndDir = IDHandler.readEdgeType(column);
    int dirID = (int) typeAndDir[1];
    long typeId = typeAndDir[0];
    Direction dir;
    RelationType rtype;
    switch(dirID) {
        case PROPERTY_DIR:
            dir = Direction.OUT;
            rtype = RelationType.PROPERTY;
            break;
        case EDGE_OUT_DIR:
            dir = Direction.OUT;
            rtype = RelationType.EDGE;
            break;
        case EDGE_IN_DIR:
            dir = Direction.IN;
            rtype = RelationType.EDGE;
            break;
        default:
            throw new IllegalArgumentException("Invalid dirID read from disk: " + dirID);
    }
    TitanType titanType = tx.getExistingType(typeId);
    InternalType def = (InternalType) titanType;
    long[] keysig = def.getSortKey();
    if (!parseHeaderOnly && !titanType.isUnique(dir)) {
        ReadBuffer sortKeyReader = def.getSortOrder() == Order.DESC ? column.invert() : column;
        readInlineTypes(keysig, properties, sortKeyReader, tx);
    }
    long relationIdDiff, vertexIdDiff = 0;
    if (titanType.isUnique(dir)) {
        if (rtype == RelationType.EDGE)
            vertexIdDiff = VariableLong.read(value);
        relationIdDiff = VariableLong.read(value);
    } else {
        // Move position to end to read backwards
        column.movePosition(column.length() - column.getPosition() - 1);
        relationIdDiff = VariableLong.readBackward(column);
        if (rtype == RelationType.EDGE)
            vertexIdDiff = VariableLong.readBackward(column);
    }
    assert relationIdDiff + vertexid > 0;
    long relationId = relationIdDiff + vertexid;
    Object other;
    switch(rtype) {
        case EDGE:
            Preconditions.checkArgument(titanType.isEdgeLabel());
            other = vertexid + vertexIdDiff;
            break;
        case PROPERTY:
            Preconditions.checkArgument(titanType.isPropertyKey());
            TitanKey key = ((TitanKey) titanType);
            other = hasGenericDataType(key) ? serializer.readClassAndObject(value) : serializer.readObjectNotNull(value, key.getDataType());
            break;
        default:
            throw new AssertionError();
    }
    assert other != null;
    if (!parseHeaderOnly) {
        // value signature & sort key if unique
        if (titanType.isUnique(dir)) {
            readInlineTypes(keysig, properties, value, tx);
        }
        readInlineTypes(def.getSignature(), properties, value, tx);
        // Third: read rest
        while (value.hasRemaining()) {
            TitanType type = tx.getExistingType(IDHandler.readInlineEdgeType(value));
            Object pvalue = readInline(value, type);
            assert pvalue != null;
            properties.put(type.getID(), pvalue);
        }
    }
    return new RelationCache(dir, typeId, relationId, other, properties);
}
Also used : RelationCache(com.thinkaurelius.titan.graphdb.relations.RelationCache) LongObjectOpenHashMap(com.carrotsearch.hppc.LongObjectOpenHashMap) EdgeDirection(com.thinkaurelius.titan.graphdb.relations.EdgeDirection) Direction(com.tinkerpop.blueprints.Direction) InternalType(com.thinkaurelius.titan.graphdb.internal.InternalType) ReadBuffer(com.thinkaurelius.titan.diskstorage.ReadBuffer) RelationType(com.thinkaurelius.titan.graphdb.internal.RelationType)

Aggregations

LongObjectOpenHashMap (com.carrotsearch.hppc.LongObjectOpenHashMap)1 ReadBuffer (com.thinkaurelius.titan.diskstorage.ReadBuffer)1 InternalType (com.thinkaurelius.titan.graphdb.internal.InternalType)1 RelationType (com.thinkaurelius.titan.graphdb.internal.RelationType)1 EdgeDirection (com.thinkaurelius.titan.graphdb.relations.EdgeDirection)1 RelationCache (com.thinkaurelius.titan.graphdb.relations.RelationCache)1 Direction (com.tinkerpop.blueprints.Direction)1