Search in sources :

Example 1 with BinaryId

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

the class BinarySerializer method writeQueryEdgePrefixCondition.

private Query writeQueryEdgePrefixCondition(ConditionQuery cq) {
    int count = 0;
    BytesBuffer buffer = BytesBuffer.allocate(BytesBuffer.BUF_EDGE_ID);
    for (HugeKeys key : EdgeId.KEYS) {
        Object value = cq.condition(key);
        if (value != null) {
            count++;
        } else {
            if (key == HugeKeys.DIRECTION) {
                // Direction is null, set to OUT
                value = Directions.OUT;
            } else {
                break;
            }
        }
        if (key == HugeKeys.OWNER_VERTEX || key == HugeKeys.OTHER_VERTEX) {
            writePartitionedId(HugeType.EDGE, (Id) value, buffer);
        } else if (key == HugeKeys.DIRECTION) {
            byte t = ((Directions) value).type().code();
            buffer.write(t);
        } else if (key == HugeKeys.LABEL) {
            assert value instanceof Id;
            buffer.writeId((Id) value);
        } else if (key == HugeKeys.SORT_VALUES) {
            assert value instanceof String;
            buffer.writeStringWithEnding((String) value);
        } else {
            assert false : key;
        }
    }
    if (count > 0) {
        assert count == cq.conditionsSize();
        return prefixQuery(cq, new BinaryId(buffer.bytes(), null));
    }
    return null;
}
Also used : BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId) Directions(com.baidu.hugegraph.type.define.Directions) BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) HugeKeys(com.baidu.hugegraph.type.define.HugeKeys)

Example 2 with BinaryId

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

the class BinarySerializer method newBackendEntry.

@Override
protected BinaryBackendEntry newBackendEntry(HugeType type, Id id) {
    if (type.isVertex()) {
        BytesBuffer buffer = BytesBuffer.allocate(2 + 1 + id.length());
        writePartitionedId(HugeType.VERTEX, id, buffer);
        return new BinaryBackendEntry(type, new BinaryId(buffer.bytes(), id));
    }
    if (type.isEdge()) {
        E.checkState(id instanceof BinaryId, "Expect a BinaryId for BackendEntry with edge id");
        return new BinaryBackendEntry(type, (BinaryId) id);
    }
    if (type.isIndex()) {
        if (this.enablePartition) {
            if (type.isStringIndex()) {
            // TODO: add string index partition
            }
            if (type.isNumericIndex()) {
            // TODO: add numeric index partition
            }
        }
        BytesBuffer buffer = BytesBuffer.allocate(1 + id.length());
        byte[] idBytes = buffer.writeIndexId(id, type).bytes();
        return new BinaryBackendEntry(type, new BinaryId(idBytes, id));
    }
    BytesBuffer buffer = BytesBuffer.allocate(1 + id.length());
    byte[] idBytes = buffer.writeId(id).bytes();
    return new BinaryBackendEntry(type, new BinaryId(idBytes, id));
}
Also used : BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId)

Example 3 with BinaryId

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

the class BytesBuffer method parseId.

public BinaryId parseId(HugeType type, boolean enablePartition) {
    if (type.isIndex()) {
        return this.readIndexId(type);
    }
    // Parse id from bytes
    if ((type.isVertex() || type.isEdge()) && enablePartition) {
        this.readShort();
    }
    int start = this.buffer.position();
    /*
         * Since edge id in edges table doesn't prefix with leading 0x7e,
         * so readId() will return the source vertex id instead of edge id,
         * can't call: type.isEdge() ? this.readEdgeId() : this.readId();
         */
    Id id = this.readId();
    int end = this.buffer.position();
    int len = end - start;
    byte[] bytes = new byte[len];
    System.arraycopy(this.array(), start, bytes, 0, len);
    return new BinaryId(bytes, id);
}
Also used : BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId) Id(com.baidu.hugegraph.backend.id.Id)

Example 4 with BinaryId

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

the class BinarySerializer method prefixQuery.

private static Query prefixQuery(ConditionQuery query, Id prefix) {
    Query newQuery;
    if (query.paging() && !query.page().isEmpty()) {
        /*
             * If used paging and the page number is not empty, deserialize
             * the page to id and use it as the starting row for this query
             */
        byte[] position = PageState.fromString(query.page()).position();
        E.checkArgument(Bytes.compare(position, prefix.asBytes()) >= 0, "Invalid page out of lower bound");
        BinaryId start = new BinaryId(position, null);
        newQuery = new IdPrefixQuery(query, start, prefix);
    } else {
        newQuery = new IdPrefixQuery(query, prefix);
    }
    return newQuery;
}
Also used : BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId) Query(com.baidu.hugegraph.backend.query.Query) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) IdPrefixQuery(com.baidu.hugegraph.backend.query.IdPrefixQuery) IdRangeQuery(com.baidu.hugegraph.backend.query.IdRangeQuery) IdPrefixQuery(com.baidu.hugegraph.backend.query.IdPrefixQuery)

Example 5 with BinaryId

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

the class BinarySerializer method writeEdgeId.

private BinaryId writeEdgeId(Id id) {
    EdgeId edgeId;
    if (id instanceof EdgeId) {
        edgeId = (EdgeId) id;
    } else {
        edgeId = EdgeId.parse(id.asString());
    }
    BytesBuffer buffer = BytesBuffer.allocate(BytesBuffer.BUF_EDGE_ID);
    if (this.enablePartition) {
        buffer.writeShort(getPartition(HugeType.EDGE, edgeId.ownerVertexId()));
        buffer.writeEdgeId(edgeId);
    } else {
        buffer.writeEdgeId(edgeId);
    }
    return new BinaryId(buffer.bytes(), id);
}
Also used : BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId) EdgeId(com.baidu.hugegraph.backend.id.EdgeId)

Aggregations

BinaryId (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId)10 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)7 Id (com.baidu.hugegraph.backend.id.Id)6 IdPrefixQuery (com.baidu.hugegraph.backend.query.IdPrefixQuery)3 IdRangeQuery (com.baidu.hugegraph.backend.query.IdRangeQuery)3 Condition (com.baidu.hugegraph.backend.query.Condition)2 RangeConditions (com.baidu.hugegraph.backend.query.Condition.RangeConditions)2 Directions (com.baidu.hugegraph.type.define.Directions)2 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)1 Query (com.baidu.hugegraph.backend.query.Query)1 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)1 BackendColumn (com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn)1 HugeType (com.baidu.hugegraph.type.HugeType)1 HugeKeys (com.baidu.hugegraph.type.define.HugeKeys)1