Search in sources :

Example 6 with HugeVertex

use of com.baidu.hugegraph.structure.HugeVertex 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 HugeVertex

use of com.baidu.hugegraph.structure.HugeVertex 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 HugeVertex

use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.

the class CachedGraphTransactionTest method testEdgeCacheClearWhenDeleteVertex.

@Test
public void testEdgeCacheClearWhenDeleteVertex() {
    CachedGraphTransaction cache = this.cache();
    HugeVertex v1 = this.newVertex(IdGenerator.of(1));
    HugeVertex v2 = this.newVertex(IdGenerator.of(2));
    HugeVertex v3 = this.newVertex(IdGenerator.of(3));
    cache.addVertex(v1);
    cache.addVertex(v2);
    cache.commit();
    HugeEdge edge = this.newEdge(v1, v2);
    cache.addEdge(edge);
    cache.commit();
    Assert.assertTrue(cache.queryEdgesByVertex(IdGenerator.of(1)).hasNext());
    Assert.assertTrue(cache.queryEdgesByVertex(IdGenerator.of(2)).hasNext());
    Assert.assertEquals(2L, Whitebox.invoke(cache, "edgesCache", "size"));
    cache.removeVertex(v3);
    cache.commit();
    Assert.assertEquals(0L, Whitebox.invoke(cache, "edgesCache", "size"));
    Assert.assertTrue(cache.queryEdgesByVertex(IdGenerator.of(1)).hasNext());
    Assert.assertTrue(cache.queryEdgesByVertex(IdGenerator.of(2)).hasNext());
    Assert.assertEquals(2L, Whitebox.invoke(cache, "edgesCache", "size"));
    cache.removeVertex(v1);
    cache.commit();
    Assert.assertEquals(0L, Whitebox.invoke(cache, "edgesCache", "size"));
    Assert.assertFalse(cache.queryEdgesByVertex(IdGenerator.of(2)).hasNext());
}
Also used : CachedGraphTransaction(com.baidu.hugegraph.backend.cache.CachedGraphTransaction) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 9 with HugeVertex

use of com.baidu.hugegraph.structure.HugeVertex 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 10 with HugeVertex

use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.

the class TableSerializer method readVertex.

@Override
public HugeVertex readVertex(HugeGraph graph, BackendEntry backendEntry) {
    E.checkNotNull(graph, "serializer graph");
    if (backendEntry == null) {
        return null;
    }
    TableBackendEntry entry = this.convertEntry(backendEntry);
    assert entry.type().isVertex();
    Id id = this.readId(entry.column(HugeKeys.ID));
    Number label = entry.column(HugeKeys.LABEL);
    Number expiredTime = entry.column(HugeKeys.EXPIRED_TIME);
    VertexLabel vertexLabel = VertexLabel.NONE;
    if (label != null) {
        vertexLabel = graph.vertexLabelOrNone(this.toId(label));
    }
    HugeVertex vertex = new HugeVertex(graph, id, vertexLabel);
    // Parse all properties of a Vertex
    this.parseProperties(vertex, entry.row());
    // Parse all edges of a Vertex
    for (TableBackendEntry.Row edge : entry.subRows()) {
        this.parseEdge(edge, vertex, graph);
    }
    // The expired time is null when this is fake vertex of edge or non-ttl
    if (expiredTime != null) {
        vertex.expiredTime(expiredTime.longValue());
    }
    return vertex;
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Id(com.baidu.hugegraph.backend.id.Id) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Aggregations

HugeVertex (com.baidu.hugegraph.structure.HugeVertex)58 Id (com.baidu.hugegraph.backend.id.Id)27 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)26 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)18 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)16 Test (org.junit.Test)16 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)11 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)10 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)9 HugeGraph (com.baidu.hugegraph.HugeGraph)8 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)8 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)8 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)7 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)7 Edge (org.apache.tinkerpop.gremlin.structure.Edge)7 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)6 HugeException (com.baidu.hugegraph.HugeException)5 HugeConfig (com.baidu.hugegraph.config.HugeConfig)5 HugeProperty (com.baidu.hugegraph.structure.HugeProperty)4 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)3