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;
}
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;
}
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);
}
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;
}
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);
}
Aggregations