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