Search in sources :

Example 36 with Id

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

the class HugeVertex method properties.

@Watched(prefix = "vertex")
// (VertexProperty<V>) prop
@SuppressWarnings("unchecked")
@Override
public <V> Iterator<VertexProperty<V>> properties(String... keys) {
    // TODO: Compatible with TinkerPop properties() (HugeGraph-742)
    this.ensureFilledProperties(true);
    // Capacity should be about the following size
    int propsCapacity = keys.length == 0 ? this.sizeOfProperties() : keys.length;
    List<VertexProperty<V>> props = new ArrayList<>(propsCapacity);
    if (keys.length == 0) {
        for (HugeProperty<?> prop : this.getProperties()) {
            assert prop instanceof VertexProperty;
            props.add((VertexProperty<V>) prop);
        }
    } else {
        for (String key : keys) {
            Id pkeyId;
            try {
                pkeyId = this.graph().propertyKey(key).id();
            } catch (IllegalArgumentException ignored) {
                continue;
            }
            HugeProperty<?> prop = this.getProperty(pkeyId);
            if (prop == null) {
                // Not found
                continue;
            }
            assert prop instanceof VertexProperty;
            props.add((VertexProperty<V>) prop);
        }
    }
    return props.iterator();
}
Also used : ArrayList(java.util.ArrayList) Id(com.baidu.hugegraph.backend.id.Id) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 37 with Id

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

the class HugeVertex method primaryValues.

@Watched(prefix = "vertex")
protected List<Object> primaryValues() {
    E.checkArgument(this.label.idStrategy() == IdStrategy.PRIMARY_KEY, "The id strategy '%s' don't have primary keys", this.label.idStrategy());
    List<Id> primaryKeys = this.label.primaryKeys();
    E.checkArgument(!primaryKeys.isEmpty(), "Primary key can't be empty for id strategy '%s'", IdStrategy.PRIMARY_KEY);
    boolean encodeNumber = this.graph().option(CoreOptions.VERTEX_ENCODE_PK_NUMBER);
    List<Object> propValues = new ArrayList<>(primaryKeys.size());
    for (Id pk : primaryKeys) {
        HugeProperty<?> property = this.getProperty(pk);
        E.checkState(property != null, "The value of primary key '%s' can't be null", this.graph().propertyKey(pk).name());
        Object propValue = property.serialValue(encodeNumber);
        if (Strings.EMPTY.equals(propValue)) {
            propValue = ConditionQuery.INDEX_VALUE_EMPTY;
        }
        propValues.add(propValue);
    }
    return propValues;
}
Also used : ArrayList(java.util.ArrayList) Id(com.baidu.hugegraph.backend.id.Id) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 38 with Id

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

the class HugeVertex method constructEdge.

public HugeEdge constructEdge(String label, HugeVertex vertex, Object... keyValues) {
    ElementKeys elemKeys = HugeElement.classifyKeys(keyValues);
    // Check id (must be null)
    if (elemKeys.id() != null) {
        throw Edge.Exceptions.userSuppliedIdsNotSupported();
    }
    Id id = null;
    // Check target vertex
    E.checkArgumentNotNull(vertex, "Target vertex can't be null");
    // Check label
    E.checkArgument(label != null && !label.isEmpty(), "Edge label can't be null or empty");
    EdgeLabel edgeLabel = this.graph().edgeLabel(label);
    // Check link
    E.checkArgument(edgeLabel.checkLinkEqual(this.schemaLabel().id(), vertex.schemaLabel().id()), "Undefined link of edge label '%s': '%s' -> '%s'", label, this.label(), vertex.label());
    // Check sortKeys
    List<Id> keys = this.graph().mapPkName2Id(elemKeys.keys());
    E.checkArgument(keys.containsAll(edgeLabel.sortKeys()), "The sort key(s) must be set for the edge " + "with label: '%s'", edgeLabel.name());
    // Check whether passed all non-null props
    @SuppressWarnings("unchecked") Collection<Id> nonNullKeys = CollectionUtils.subtract(edgeLabel.properties(), edgeLabel.nullableKeys());
    if (!keys.containsAll(nonNullKeys)) {
        @SuppressWarnings("unchecked") Collection<Id> missed = CollectionUtils.subtract(nonNullKeys, keys);
        E.checkArgument(false, "All non-null property keys: %s " + "of edge label '%s' must be set, " + "but missed keys: %s", this.graph().mapPkId2Name(nonNullKeys), edgeLabel.name(), this.graph().mapPkId2Name(missed));
    }
    HugeEdge edge = new HugeEdge(this, id, edgeLabel, vertex);
    // Set properties
    ElementHelper.attachProperties(edge, keyValues);
    edge.assignId();
    return edge;
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) Id(com.baidu.hugegraph.backend.id.Id)

Example 39 with Id

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

the class IndexLabelRebuildJob method schemaElement.

private SchemaElement schemaElement() {
    HugeType type = this.schemaType();
    Id id = this.schemaId();
    switch(type) {
        case VERTEX_LABEL:
            return this.graph().vertexLabel(id);
        case EDGE_LABEL:
            return this.graph().edgeLabel(id);
        case INDEX_LABEL:
            return this.graph().indexLabel(id);
        default:
            throw new AssertionError(String.format("Invalid HugeType '%s' for rebuild", type));
    }
}
Also used : Id(com.baidu.hugegraph.backend.id.Id) HugeType(com.baidu.hugegraph.type.HugeType)

Example 40 with Id

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

the class OlapPropertyKeyClearJob method execute.

@Override
public Object execute() {
    Id olap = this.schemaId();
    // Clear olap data table
    this.params().graphTransaction().clearOlapPk(olap);
    // Clear corresponding index data
    clearIndexLabel(this.params(), olap);
    return null;
}
Also used : Id(com.baidu.hugegraph.backend.id.Id)

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