Search in sources :

Example 1 with VertexLabel

use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.

the class HugeGraph method mapVlName2Id.

default Id[] mapVlName2Id(String[] vertexLabels) {
    Id[] ids = new Id[vertexLabels.length];
    for (int i = 0; i < vertexLabels.length; i++) {
        VertexLabel vertexLabel = this.vertexLabel(vertexLabels[i]);
        ids[i] = vertexLabel.id();
    }
    return ids;
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) Id(com.baidu.hugegraph.backend.id.Id)

Example 2 with VertexLabel

use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.

the class RelationshipManager method newVertex.

private HugeVertex newVertex(Object id, String label) {
    VertexLabel vl = this.graph().vertexLabel(label);
    Id idValue = HugeVertex.getIdValue(id);
    return HugeVertex.create(this.tx(), idValue, vl);
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) Id(com.baidu.hugegraph.backend.id.Id)

Example 3 with VertexLabel

use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.

the class ServerInfoManager method serverInfos.

private Iterator<HugeServerInfo> serverInfos(Map<String, Object> conditions, long limit, String page) {
    return this.call(() -> {
        ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
        if (page != null) {
            query.page(page);
        }
        HugeGraph graph = this.graph.graph();
        VertexLabel vl = graph.vertexLabel(HugeServerInfo.P.SERVER);
        query.eq(HugeKeys.LABEL, vl.id());
        for (Map.Entry<String, Object> entry : conditions.entrySet()) {
            PropertyKey pk = graph.propertyKey(entry.getKey());
            query.query(Condition.eq(pk.id(), entry.getValue()));
        }
        query.showHidden(true);
        if (limit != NO_LIMIT) {
            query.limit(limit);
        }
        Iterator<Vertex> vertices = this.tx().queryVertices(query);
        Iterator<HugeServerInfo> servers = new MapperIterator<>(vertices, HugeServerInfo::fromVertex);
        // Convert iterator to list to avoid across thread tx accessed
        return QueryResults.toList(servers);
    });
}
Also used : HugeVertex(com.baidu.hugegraph.structure.HugeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HugeGraph(com.baidu.hugegraph.HugeGraph) MapperIterator(com.baidu.hugegraph.iterator.MapperIterator) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 4 with VertexLabel

use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.

the class StandardTaskScheduler method queryTask.

private <V> Iterator<HugeTask<V>> queryTask(Map<String, Object> conditions, long limit, String page) {
    return this.call(() -> {
        ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
        if (page != null) {
            query.page(page);
        }
        VertexLabel vl = this.graph().vertexLabel(P.TASK);
        query.eq(HugeKeys.LABEL, vl.id());
        for (Map.Entry<String, Object> entry : conditions.entrySet()) {
            PropertyKey pk = this.graph().propertyKey(entry.getKey());
            query.query(Condition.eq(pk.id(), entry.getValue()));
        }
        query.showHidden(true);
        if (limit != NO_LIMIT) {
            query.limit(limit);
        }
        Iterator<Vertex> vertices = this.tx().queryVertices(query);
        Iterator<HugeTask<V>> tasks = new MapperIterator<>(vertices, HugeTask::fromVertex);
        // Convert iterator to list to avoid across thread tx accessed
        return QueryResults.toList(tasks);
    });
}
Also used : HugeVertex(com.baidu.hugegraph.structure.HugeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) MapperIterator(com.baidu.hugegraph.iterator.MapperIterator) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 5 with VertexLabel

use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.

the class IndexLabelBuilder method checkPrimaryKeyIndex.

private void checkPrimaryKeyIndex(SchemaLabel schemaLabel) {
    if (schemaLabel instanceof VertexLabel) {
        VertexLabel vl = (VertexLabel) schemaLabel;
        if (vl.idStrategy().isPrimaryKey()) {
            if (this.indexType.isSecondary() || this.indexType.isUnique() || this.indexType.isShard() && this.allStringIndex(this.indexFields)) {
                List<String> pks = this.graph().mapPkId2Name(vl.primaryKeys());
                E.checkArgument(!this.indexFields.containsAll(pks), "No need to build index on properties " + "%s, because they contains all primary " + "keys %s for vertex label '%s'", this.indexFields, pks, vl.name());
            }
        }
    }
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel)

Aggregations

VertexLabel (com.baidu.hugegraph.schema.VertexLabel)86 Test (org.junit.Test)35 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)27 Id (com.baidu.hugegraph.backend.id.Id)23 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)20 HugeGraph (com.baidu.hugegraph.HugeGraph)19 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)19 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)12 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)12 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)11 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)7 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)6 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)5 Timed (com.codahale.metrics.annotation.Timed)5 RolesAllowed (jakarta.annotation.security.RolesAllowed)5 Produces (jakarta.ws.rs.Produces)5 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)4 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)4 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)4 Date (java.util.Date)4