Search in sources :

Example 21 with PropertyKey

use of com.baidu.hugegraph.schema.PropertyKey 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 22 with PropertyKey

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

the class FakeObjects method newPropertyKey.

public PropertyKey newPropertyKey(Id id, String name, DataType dataType, Cardinality cardinality) {
    PropertyKey schema = new PropertyKey(this.graph, id, name);
    schema.dataType(dataType);
    schema.cardinality(cardinality);
    Mockito.when(this.graph.propertyKey(id)).thenReturn(schema);
    Mockito.when(this.graph.propertyKey(name)).thenReturn(schema);
    return schema;
}
Also used : PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 23 with PropertyKey

use of com.baidu.hugegraph.schema.PropertyKey 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 24 with PropertyKey

use of com.baidu.hugegraph.schema.PropertyKey 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 25 with PropertyKey

use of com.baidu.hugegraph.schema.PropertyKey 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)

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