Search in sources :

Example 6 with EdgeLabel

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

the class FakeObjects method newEdge.

public HugeEdge newEdge(long sourceVertexId, long targetVertexId) {
    PropertyKey name = this.newPropertyKey(IdGenerator.of(1), "name");
    PropertyKey age = this.newPropertyKey(IdGenerator.of(2), "age", DataType.INT, Cardinality.SINGLE);
    PropertyKey city = this.newPropertyKey(IdGenerator.of(3), "city");
    PropertyKey date = this.newPropertyKey(IdGenerator.of(4), "date", DataType.DATE);
    PropertyKey weight = this.newPropertyKey(IdGenerator.of(5), "weight", DataType.DOUBLE);
    VertexLabel vl = this.newVertexLabel(IdGenerator.of(1), "person", IdStrategy.CUSTOMIZE_NUMBER, name.id(), age.id(), city.id());
    EdgeLabel el = this.newEdgeLabel(IdGenerator.of(1), "knows", Frequency.SINGLE, vl.id(), vl.id(), date.id(), weight.id());
    HugeVertex source = new HugeVertex(this.graph(), IdGenerator.of(sourceVertexId), vl);
    source.addProperty(name, "tom");
    source.addProperty(age, 18);
    source.addProperty(city, "Beijing");
    HugeVertex target = new HugeVertex(this.graph(), IdGenerator.of(targetVertexId), vl);
    target.addProperty(name, "cat");
    target.addProperty(age, 20);
    target.addProperty(city, "Shanghai");
    Id id = EdgeId.parse("L123456>1>>L987654");
    HugeEdge edge = new HugeEdge(this.graph(), id, el);
    Whitebox.setInternalState(edge, "sourceVertex", source);
    Whitebox.setInternalState(edge, "targetVertex", target);
    edge.assignId();
    edge.addProperty(date, new Date());
    edge.addProperty(weight, 0.75);
    return edge;
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Id(com.baidu.hugegraph.backend.id.Id) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Date(java.util.Date)

Example 7 with EdgeLabel

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

the class FakeObjects method newEdge.

public HugeEdge newEdge(String sourceVertexId, String targetVertexId) {
    PropertyKey name = this.newPropertyKey(IdGenerator.of(1), "name");
    PropertyKey age = this.newPropertyKey(IdGenerator.of(2), "age", DataType.INT, Cardinality.SINGLE);
    PropertyKey city = this.newPropertyKey(IdGenerator.of(3), "city");
    PropertyKey date = this.newPropertyKey(IdGenerator.of(4), "date", DataType.DATE);
    PropertyKey weight = this.newPropertyKey(IdGenerator.of(5), "weight", DataType.DOUBLE);
    VertexLabel vl = this.newVertexLabel(IdGenerator.of(1), "person", IdStrategy.CUSTOMIZE_NUMBER, name.id(), age.id(), city.id());
    EdgeLabel el = this.newEdgeLabel(IdGenerator.of(1), "knows", Frequency.SINGLE, vl.id(), vl.id(), date.id(), weight.id());
    HugeVertex source = new HugeVertex(this.graph(), IdGenerator.of(sourceVertexId), vl);
    source.addProperty(name, "tom");
    source.addProperty(age, 18);
    source.addProperty(city, "Beijing");
    HugeVertex target = new HugeVertex(this.graph(), IdGenerator.of(targetVertexId), vl);
    target.addProperty(name, "cat");
    target.addProperty(age, 20);
    target.addProperty(city, "Shanghai");
    Id id = EdgeId.parse("L123456>1>>L987654");
    HugeEdge edge = new HugeEdge(this.graph(), id, el);
    Whitebox.setInternalState(edge, "sourceVertex", source);
    Whitebox.setInternalState(edge, "targetVertex", target);
    edge.assignId();
    edge.addProperty(date, new Date());
    edge.addProperty(weight, 0.75);
    return edge;
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Id(com.baidu.hugegraph.backend.id.Id) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Date(java.util.Date)

Example 8 with EdgeLabel

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

the class FakeObjects method newEdgeLabel.

public EdgeLabel newEdgeLabel(Id id, String name, Frequency frequency, Id sourceLabel, Id targetLabel, Id... properties) {
    EdgeLabel schema = new EdgeLabel(this.graph, id, name);
    schema.frequency(frequency);
    schema.sourceLabel(sourceLabel);
    schema.targetLabel(targetLabel);
    schema.properties(properties);
    Mockito.when(this.graph.edgeLabel(id)).thenReturn(schema);
    Mockito.when(this.graph.edgeLabelOrNone(id)).thenReturn(schema);
    return schema;
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel)

Example 9 with EdgeLabel

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

the class TableSerializer method readEdgeLabel.

@Override
public EdgeLabel readEdgeLabel(HugeGraph graph, BackendEntry backendEntry) {
    if (backendEntry == null) {
        return null;
    }
    TableBackendEntry entry = this.convertEntry(backendEntry);
    Number id = schemaColumn(entry, HugeKeys.ID);
    String name = schemaColumn(entry, HugeKeys.NAME);
    Frequency frequency = schemaEnum(entry, HugeKeys.FREQUENCY, Frequency.class);
    Number sourceLabel = schemaColumn(entry, HugeKeys.SOURCE_LABEL);
    Number targetLabel = schemaColumn(entry, HugeKeys.TARGET_LABEL);
    Object sortKeys = schemaColumn(entry, HugeKeys.SORT_KEYS);
    Object nullableKeys = schemaColumn(entry, HugeKeys.NULLABLE_KEYS);
    Object properties = schemaColumn(entry, HugeKeys.PROPERTIES);
    Object indexLabels = schemaColumn(entry, HugeKeys.INDEX_LABELS);
    SchemaStatus status = schemaEnum(entry, HugeKeys.STATUS, SchemaStatus.class);
    Number ttl = schemaColumn(entry, HugeKeys.TTL);
    Number ttlStartTime = schemaColumn(entry, HugeKeys.TTL_START_TIME);
    EdgeLabel edgeLabel = new EdgeLabel(graph, this.toId(id), name);
    edgeLabel.frequency(frequency);
    edgeLabel.sourceLabel(this.toId(sourceLabel));
    edgeLabel.targetLabel(this.toId(targetLabel));
    edgeLabel.properties(this.toIdArray(properties));
    edgeLabel.sortKeys(this.toIdArray(sortKeys));
    edgeLabel.nullableKeys(this.toIdArray(nullableKeys));
    edgeLabel.addIndexLabels(this.toIdArray(indexLabels));
    edgeLabel.status(status);
    edgeLabel.ttl(ttl.longValue());
    edgeLabel.ttlStartTime(this.toId(ttlStartTime));
    this.readEnableLabelIndex(edgeLabel, entry);
    this.readUserdata(edgeLabel, entry);
    return edgeLabel;
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) Frequency(com.baidu.hugegraph.type.define.Frequency) SchemaStatus(com.baidu.hugegraph.type.define.SchemaStatus)

Example 10 with EdgeLabel

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

the class TableSerializer method parseEdge.

/**
 * Parse an edge from a entry row
 * @param row edge entry
 * @param vertex null or the source vertex
 * @param graph the HugeGraph context object
 * @return the source vertex
 */
protected HugeEdge parseEdge(TableBackendEntry.Row row, HugeVertex vertex, HugeGraph graph) {
    Object ownerVertexId = row.column(HugeKeys.OWNER_VERTEX);
    Number dir = row.column(HugeKeys.DIRECTION);
    boolean direction = EdgeId.isOutDirectionFromCode(dir.byteValue());
    Number label = row.column(HugeKeys.LABEL);
    String sortValues = row.column(HugeKeys.SORT_VALUES);
    Object otherVertexId = row.column(HugeKeys.OTHER_VERTEX);
    Number expiredTime = row.column(HugeKeys.EXPIRED_TIME);
    if (vertex == null) {
        Id ownerId = this.readId(ownerVertexId);
        vertex = new HugeVertex(graph, ownerId, VertexLabel.NONE);
    }
    EdgeLabel edgeLabel = graph.edgeLabelOrNone(this.toId(label));
    Id otherId = this.readId(otherVertexId);
    // Construct edge
    HugeEdge edge = HugeEdge.constructEdge(vertex, direction, edgeLabel, sortValues, otherId);
    // Parse edge properties
    this.parseProperties(edge, row);
    // The expired time is null when the edge is non-ttl
    long expired = edge.hasTtl() ? expiredTime.longValue() : 0L;
    edge.expiredTime(expired);
    return edge;
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Id(com.baidu.hugegraph.backend.id.Id) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Aggregations

EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)58 Test (org.junit.Test)22 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)19 Id (com.baidu.hugegraph.backend.id.Id)16 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)12 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)11 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)11 HugeGraph (com.baidu.hugegraph.HugeGraph)10 Edge (org.apache.tinkerpop.gremlin.structure.Edge)10 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)8 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)7 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)6 Timed (com.codahale.metrics.annotation.Timed)5 RolesAllowed (jakarta.annotation.security.RolesAllowed)5 Produces (jakarta.ws.rs.Produces)5 Date (java.util.Date)4 GraphTransaction (com.baidu.hugegraph.backend.tx.GraphTransaction)3 SchemaTransaction (com.baidu.hugegraph.backend.tx.SchemaTransaction)3 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)3 SchemaStatus (com.baidu.hugegraph.type.define.SchemaStatus)3