Search in sources :

Example 1 with HugeProperty

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

the class CassandraSerializer method writeOlapVertex.

@Override
public BackendEntry writeOlapVertex(HugeVertex vertex) {
    CassandraBackendEntry entry = newBackendEntry(HugeType.OLAP, vertex.id());
    entry.column(HugeKeys.ID, this.writeId(vertex.id()));
    Collection<HugeProperty<?>> properties = vertex.getProperties();
    E.checkArgument(properties.size() == 1, "Expect only 1 property for olap vertex, but got %s", properties.size());
    HugeProperty<?> property = properties.iterator().next();
    PropertyKey pk = property.propertyKey();
    entry.subId(pk.id());
    entry.column(HugeKeys.PROPERTY_VALUE, this.writeProperty(pk, property.value()));
    entry.olap(true);
    return entry;
}
Also used : HugeProperty(com.baidu.hugegraph.structure.HugeProperty) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 2 with HugeProperty

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

the class BinarySerializer method writeOlapVertex.

@Override
public BackendEntry writeOlapVertex(HugeVertex vertex) {
    BinaryBackendEntry entry = newBackendEntry(HugeType.OLAP, vertex.id());
    BytesBuffer buffer = BytesBuffer.allocate(8 + 16);
    Collection<HugeProperty<?>> properties = vertex.getProperties();
    if (properties.size() != 1) {
        E.checkArgument(false, "Expect 1 property for olap vertex, but got %s", properties.size());
    }
    HugeProperty<?> property = properties.iterator().next();
    PropertyKey propertyKey = property.propertyKey();
    buffer.writeVInt(SchemaElement.schemaId(propertyKey.id()));
    buffer.writeProperty(propertyKey, property.value());
    // Fill column
    byte[] name = this.keyWithIdPrefix ? entry.id().asBytes() : BytesBuffer.BYTES_EMPTY;
    entry.column(name, buffer.bytes());
    entry.subId(propertyKey.id());
    entry.olap(true);
    return entry;
}
Also used : HugeProperty(com.baidu.hugegraph.structure.HugeProperty) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 3 with HugeProperty

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

the class JsonUtilTest method testSerializeVertexWithNumberId.

@Test
public void testSerializeVertexWithNumberId() {
    FakeObjects fakeObject = new FakeObjects();
    PropertyKey name = fakeObject.newPropertyKey(IdGenerator.of(1), "name");
    PropertyKey age = fakeObject.newPropertyKey(IdGenerator.of(2), "age", DataType.INT, Cardinality.SINGLE);
    PropertyKey city = fakeObject.newPropertyKey(IdGenerator.of(3), "city");
    VertexLabel vl = fakeObject.newVertexLabel(IdGenerator.of(1), "person", IdStrategy.CUSTOMIZE_NUMBER, name.id(), age.id(), city.id());
    Id id = IdGenerator.of(123456L);
    HugeVertex vertex = new HugeVertex(fakeObject.graph(), id, vl);
    MutableIntObjectMap<HugeProperty<?>> properties = CollectionFactory.newIntObjectMap(name.id(), new HugeVertexProperty<>(vertex, name, "marko"), age.id(), new HugeVertexProperty<>(vertex, age, 29), city.id(), new HugeVertexProperty<>(vertex, city, "Beijing"));
    Whitebox.setInternalState(vertex, "properties", properties);
    String json = JsonUtil.toJson(vertex);
    Assert.assertEquals("{\"id\":123456,\"label\":\"person\"," + "\"type\":\"vertex\",\"properties\":{\"" + "name\":\"marko\",\"age\":29," + "\"city\":\"Beijing\"}}", json);
}
Also used : HugeProperty(com.baidu.hugegraph.structure.HugeProperty) FakeObjects(com.baidu.hugegraph.unit.FakeObjects) 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) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 4 with HugeProperty

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

the class GraphTransaction method constructVertex.

@Watched(prefix = "graph")
public HugeVertex constructVertex(boolean verifyVL, Object... keyValues) {
    HugeElement.ElementKeys elemKeys = HugeElement.classifyKeys(keyValues);
    if (possibleOlapVertex(elemKeys)) {
        Id id = HugeVertex.getIdValue(elemKeys.id());
        HugeVertex vertex = HugeVertex.create(this, id, VertexLabel.OLAP_VL);
        ElementHelper.attachProperties(vertex, keyValues);
        Iterator<HugeProperty<?>> iterator = vertex.getProperties().iterator();
        assert iterator.hasNext();
        if (iterator.next().propertyKey().olap()) {
            return vertex;
        }
    }
    VertexLabel vertexLabel = this.checkVertexLabel(elemKeys.label(), verifyVL);
    Id id = HugeVertex.getIdValue(elemKeys.id());
    List<Id> keys = this.graph().mapPkName2Id(elemKeys.keys());
    // Check whether id match with id strategy
    this.checkId(id, keys, vertexLabel);
    // Create HugeVertex
    HugeVertex vertex = HugeVertex.create(this, null, vertexLabel);
    // Set properties
    ElementHelper.attachProperties(vertex, keyValues);
    // Assign vertex id
    if (this.params().mode().maintaining() && vertexLabel.idStrategy() == IdStrategy.AUTOMATIC) {
        // Resume id for AUTOMATIC id strategy in restoring mode
        vertex.assignId(id, true);
    } else {
        vertex.assignId(id);
    }
    return vertex;
}
Also used : HugeProperty(com.baidu.hugegraph.structure.HugeProperty) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) HugeElement(com.baidu.hugegraph.structure.HugeElement) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 5 with HugeProperty

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

the class JsonUtilTest method testSerializeEdge.

@Test
public void testSerializeEdge() {
    FakeObjects fakeObject = new FakeObjects();
    PropertyKey name = fakeObject.newPropertyKey(IdGenerator.of(1), "name");
    PropertyKey age = fakeObject.newPropertyKey(IdGenerator.of(2), "age", DataType.INT, Cardinality.SINGLE);
    PropertyKey city = fakeObject.newPropertyKey(IdGenerator.of(3), "city");
    PropertyKey date = fakeObject.newPropertyKey(IdGenerator.of(4), "date", DataType.DATE);
    PropertyKey weight = fakeObject.newPropertyKey(IdGenerator.of(5), "weight", DataType.DOUBLE);
    VertexLabel vl = fakeObject.newVertexLabel(IdGenerator.of(1), "person", IdStrategy.CUSTOMIZE_NUMBER, name.id(), age.id(), city.id());
    EdgeLabel el = fakeObject.newEdgeLabel(IdGenerator.of(1), "knows", Frequency.SINGLE, vl.id(), vl.id(), date.id(), weight.id());
    HugeVertex source = new HugeVertex(fakeObject.graph(), IdGenerator.of(123456), vl);
    HugeVertex target = new HugeVertex(fakeObject.graph(), IdGenerator.of(987654), vl);
    Id id = EdgeId.parse("L123456>1>>L987654");
    HugeEdge edge = new HugeEdge(fakeObject.graph(), id, el);
    Whitebox.setInternalState(edge, "sourceVertex", source);
    Whitebox.setInternalState(edge, "targetVertex", target);
    Date dateValue = Utils.date("2019-03-12");
    MutableIntObjectMap<HugeProperty<?>> properties = CollectionFactory.newIntObjectMap(date.id(), new HugeEdgeProperty<>(edge, date, dateValue), weight.id(), new HugeEdgeProperty<>(edge, weight, 0.8));
    Whitebox.setInternalState(edge, "properties", properties);
    String json = JsonUtil.toJson(edge);
    Assert.assertEquals("{\"id\":\"L123456>1>>L987654\"," + "\"label\":\"knows\",\"type\":\"edge\"," + "\"outV\":123456,\"outVLabel\":\"person\"," + "\"inV\":987654,\"inVLabel\":\"person\"," + "\"properties\":{\"date\":" + "\"2019-03-12 00:00:00.000\"," + "\"weight\":0.8}}", json);
}
Also used : HugeProperty(com.baidu.hugegraph.structure.HugeProperty) FakeObjects(com.baidu.hugegraph.unit.FakeObjects) 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) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Aggregations

HugeProperty (com.baidu.hugegraph.structure.HugeProperty)5 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)4 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)3 Id (com.baidu.hugegraph.backend.id.Id)3 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)3 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)3 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)2 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)2 Test (org.junit.Test)2 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)1 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)1 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)1 HugeElement (com.baidu.hugegraph.structure.HugeElement)1 Date (java.util.Date)1