Search in sources :

Example 81 with Id

use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.

the class CassandraTable method queryId2Select.

protected List<Select> queryId2Select(Query query, Select select) {
    // Query by id(s)
    if (query.idsSize() == 0) {
        return ImmutableList.of(select);
    }
    List<HugeKeys> nameParts = this.idColumnName();
    List<List<Object>> ids = new ArrayList<>(query.idsSize());
    for (Id id : query.ids()) {
        List<Object> idParts = this.idColumnValue(id);
        if (nameParts.size() != idParts.size()) {
            throw new NotFoundException("Unsupported ID format: '%s' (should contain %s)", id, nameParts);
        }
        ids.add(idParts);
    }
    // Query only by partition-key
    if (nameParts.size() == 1) {
        List<Object> idList = new ArrayList<>(ids.size());
        for (List<Object> id : ids) {
            assert id.size() == 1;
            idList.add(id.get(0));
        }
        return this.ids2IdSelects(select, nameParts.get(0), idList);
    }
    /*
         * Query by partition-key + clustering-key
         * NOTE: Error if multi-column IN clause include partition key:
         * error: multi-column relations can only be applied to clustering
         * columns when using: select.where(QueryBuilder.in(names, idList));
         * So we use multi-query instead of IN
         */
    List<Select> selects = new ArrayList<>(ids.size());
    for (List<Object> id : ids) {
        assert nameParts.size() == id.size();
        Select idSelect = cloneSelect(select, this.table());
        /*
             * NOTE: concat with AND relation, like:
             * "pk = id and ck1 = v1 and ck2 = v2"
             */
        for (int i = 0, n = nameParts.size(); i < n; i++) {
            idSelect.where(formatEQ(nameParts.get(i), id.get(i)));
        }
        selects.add(idSelect);
    }
    return selects;
}
Also used : ArrayList(java.util.ArrayList) Select(com.datastax.driver.core.querybuilder.Select) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Id(com.baidu.hugegraph.backend.id.Id) HugeKeys(com.baidu.hugegraph.type.define.HugeKeys)

Example 82 with Id

use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.

the class BinarySerializer method readVertex.

@Override
public HugeVertex readVertex(HugeGraph graph, BackendEntry bytesEntry) {
    if (bytesEntry == null) {
        return null;
    }
    BinaryBackendEntry entry = this.convertEntry(bytesEntry);
    // Parse id
    Id id = entry.id().origin();
    Id vid = id.edge() ? ((EdgeId) id).ownerVertexId() : id;
    HugeVertex vertex = new HugeVertex(graph, vid, VertexLabel.NONE);
    // Parse all properties and edges of a Vertex
    Iterator<BackendColumn> iterator = entry.columns().iterator();
    for (int index = 0; iterator.hasNext(); index++) {
        BackendColumn col = iterator.next();
        if (entry.type().isEdge()) {
            // NOTE: the entry id type is vertex even if entry type is edge
            // Parse vertex edges
            this.parseColumn(col, vertex);
        } else {
            assert entry.type().isVertex();
            // Parse vertex properties
            assert entry.columnsSize() >= 1 : entry.columnsSize();
            if (index == 0) {
                this.parseVertex(col.value, vertex);
            } else {
                this.parseVertexOlap(col.value, vertex);
            }
        }
    }
    return vertex;
}
Also used : BackendColumn(com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn) BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Example 83 with Id

use of com.baidu.hugegraph.backend.id.Id 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 84 with Id

use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.

the class BinarySerializer method parseVertexOlap.

protected void parseVertexOlap(byte[] value, HugeVertex vertex) {
    BytesBuffer buffer = BytesBuffer.wrap(value);
    Id pkeyId = IdGenerator.of(buffer.readVInt());
    this.parseProperty(pkeyId, buffer, vertex);
}
Also used : BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId)

Example 85 with Id

use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.

the class BinarySerializer method writeStringIndexQuery.

private Query writeStringIndexQuery(ConditionQuery query) {
    E.checkArgument(query.allSysprop() && query.conditionsSize() == 2, "There should be two conditions: " + "INDEX_LABEL_ID and FIELD_VALUES" + "in secondary index query");
    Id index = query.condition(HugeKeys.INDEX_LABEL_ID);
    Object key = query.condition(HugeKeys.FIELD_VALUES);
    E.checkArgument(index != null, "Please specify the index label");
    E.checkArgument(key != null, "Please specify the index key");
    Id prefix = formatIndexId(query.resultType(), index, key, true);
    return prefixQuery(query, prefix);
}
Also used : BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId)

Aggregations

Id (com.baidu.hugegraph.backend.id.Id)381 Test (org.junit.Test)124 HugeGraph (com.baidu.hugegraph.HugeGraph)104 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)71 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)54 Timed (com.codahale.metrics.annotation.Timed)41 Produces (jakarta.ws.rs.Produces)40 AuthManager (com.baidu.hugegraph.auth.AuthManager)39 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)37 ArrayList (java.util.ArrayList)35 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)33 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)33 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)32 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)32 Directions (com.baidu.hugegraph.type.define.Directions)29 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)25 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)25 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)24 Edge (org.apache.tinkerpop.gremlin.structure.Edge)22 HugeType (com.baidu.hugegraph.type.HugeType)21