Search in sources :

Example 56 with PropertyKey

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

the class StandardHugeGraph method serverStarted.

@Override
public void serverStarted(Id serverId, NodeRole serverRole) {
    LOG.info("Init server info [{}-{}] for graph '{}'...", serverId, serverRole, this.name);
    this.serverInfoManager().initServerInfo(serverId, serverRole);
    // TODO: check necessary?
    LOG.info("Check olap property-key tables for graph '{}'", this.name);
    for (PropertyKey pk : this.schemaTransaction().getPropertyKeys()) {
        if (pk.olap()) {
            this.graphTransaction().initAndRegisterOlapTable(pk.id());
        }
    }
    LOG.info("Restoring incomplete tasks for graph '{}'...", this.name);
    this.taskScheduler().restoreTasks();
    this.started = true;
}
Also used : PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 57 with PropertyKey

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

the class HugeGraph method mapPkName2Id.

default List<Id> mapPkName2Id(Collection<String> pkeys) {
    List<Id> ids = new ArrayList<>(pkeys.size());
    for (String pkey : pkeys) {
        PropertyKey propertyKey = this.propertyKey(pkey);
        ids.add(propertyKey.id());
    }
    return ids;
}
Also used : ArrayList(java.util.ArrayList) Id(com.baidu.hugegraph.backend.id.Id) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 58 with PropertyKey

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

the class EntityManager method queryEntity.

private Iterator<Vertex> queryEntity(String label, Map<String, Object> conditions, long limit) {
    ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
    VertexLabel vl = this.graph().vertexLabel(label);
    query.eq(HugeKeys.LABEL, vl.id());
    for (Map.Entry<String, Object> entry : conditions.entrySet()) {
        PropertyKey pkey = this.graph().propertyKey(entry.getKey());
        query.query(Condition.eq(pkey.id(), entry.getValue()));
    }
    query.showHidden(true);
    if (limit != NO_LIMIT) {
        query.limit(limit);
    }
    return this.tx().queryVertices(query);
}
Also used : ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 59 with PropertyKey

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

the class RelationshipManager method queryRelationship.

private Iterator<Edge> queryRelationship(Id source, Directions direction, String label, Map<String, Object> conditions, long limit) {
    ConditionQuery query = new ConditionQuery(HugeType.EDGE);
    EdgeLabel el = this.graph().edgeLabel(label);
    if (direction == null) {
        direction = Directions.OUT;
    }
    if (source != null) {
        query.eq(HugeKeys.OWNER_VERTEX, source);
        query.eq(HugeKeys.DIRECTION, direction);
    }
    if (label != null) {
        query.eq(HugeKeys.LABEL, el.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<Edge> edges = this.tx().queryEdges(query);
    if (limit == NO_LIMIT) {
        return edges;
    }
    long[] size = new long[1];
    return new MapperIterator<>(edges, edge -> {
        if (++size[0] > limit) {
            return null;
        }
        return edge;
    });
}
Also used : MapperIterator(com.baidu.hugegraph.iterator.MapperIterator) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 60 with PropertyKey

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

the class TableSerializer method parseProperty.

protected void parseProperty(Id key, Object colValue, HugeElement owner) {
    // Get PropertyKey by PropertyKey id
    PropertyKey pkey = owner.graph().propertyKey(key);
    // Parse value
    Object value = this.readProperty(pkey, colValue);
    // Set properties of vertex/edge
    if (pkey.cardinality() == Cardinality.SINGLE) {
        owner.addProperty(pkey, value);
    } else {
        if (!(value instanceof Collection)) {
            throw new BackendException("Invalid value of non-single property: %s", value);
        }
        owner.addProperty(pkey, value);
    }
}
Also used : Collection(java.util.Collection) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) BackendException(com.baidu.hugegraph.backend.BackendException)

Aggregations

PropertyKey (com.baidu.hugegraph.schema.PropertyKey)94 Id (com.baidu.hugegraph.backend.id.Id)31 Test (org.junit.Test)24 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)20 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)15 HugeGraph (com.baidu.hugegraph.HugeGraph)13 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)11 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)9 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)9 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)9 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)7 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)7 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)6 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)6 DataType (com.baidu.hugegraph.type.define.DataType)6 Map (java.util.Map)6 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)5 Timed (com.codahale.metrics.annotation.Timed)5 RolesAllowed (jakarta.annotation.security.RolesAllowed)5 Collection (java.util.Collection)5