use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class VertexLabelCoreTest method testAddVertexWithDefaultIdStrategyAndPassedPk.
@Test
public void testAddVertexWithDefaultIdStrategyAndPassedPk() {
super.initPropertyKeys();
HugeGraph graph = graph();
SchemaManager schema = graph.schema();
VertexLabel person = schema.vertexLabel("person").properties("name", "age").primaryKeys("name").create();
Assert.assertEquals(IdStrategy.PRIMARY_KEY, person.idStrategy());
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class TableSerializer method readVertexLabel.
@Override
public VertexLabel readVertexLabel(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);
IdStrategy idStrategy = schemaEnum(entry, HugeKeys.ID_STRATEGY, IdStrategy.class);
Object properties = schemaColumn(entry, HugeKeys.PROPERTIES);
Object primaryKeys = schemaColumn(entry, HugeKeys.PRIMARY_KEYS);
Object nullableKeys = schemaColumn(entry, HugeKeys.NULLABLE_KEYS);
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);
VertexLabel vertexLabel = new VertexLabel(graph, this.toId(id), name);
vertexLabel.idStrategy(idStrategy);
vertexLabel.properties(this.toIdArray(properties));
vertexLabel.primaryKeys(this.toIdArray(primaryKeys));
vertexLabel.nullableKeys(this.toIdArray(nullableKeys));
vertexLabel.addIndexLabels(this.toIdArray(indexLabels));
vertexLabel.status(status);
vertexLabel.ttl(ttl.longValue());
vertexLabel.ttlStartTime(this.toId(ttlStartTime));
this.readEnableLabelIndex(vertexLabel, entry);
this.readUserdata(vertexLabel, entry);
return vertexLabel;
}
use of com.baidu.hugegraph.schema.VertexLabel 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;
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class TextSerializer method readVertexLabel.
@Override
public VertexLabel readVertexLabel(HugeGraph graph, BackendEntry backendEntry) {
if (backendEntry == null) {
return null;
}
TextBackendEntry entry = this.convertEntry(backendEntry);
Id id = readId(entry.id());
String name = JsonUtil.fromJson(entry.column(HugeKeys.NAME), String.class);
String idStrategy = entry.column(HugeKeys.ID_STRATEGY);
String properties = entry.column(HugeKeys.PROPERTIES);
String primaryKeys = entry.column(HugeKeys.PRIMARY_KEYS);
String nullableKeys = entry.column(HugeKeys.NULLABLE_KEYS);
String indexLabels = entry.column(HugeKeys.INDEX_LABELS);
String enableLabelIndex = entry.column(HugeKeys.ENABLE_LABEL_INDEX);
String status = entry.column(HugeKeys.STATUS);
VertexLabel vertexLabel = new VertexLabel(graph, id, name);
vertexLabel.idStrategy(JsonUtil.fromJson(idStrategy, IdStrategy.class));
vertexLabel.properties(readIds(properties));
vertexLabel.primaryKeys(readIds(primaryKeys));
vertexLabel.nullableKeys(readIds(nullableKeys));
vertexLabel.addIndexLabels(readIds(indexLabels));
vertexLabel.enableLabelIndex(JsonUtil.fromJson(enableLabelIndex, Boolean.class));
readUserdata(vertexLabel, entry);
vertexLabel.status(JsonUtil.fromJson(status, SchemaStatus.class));
return vertexLabel;
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class TextSerializer method readVertex.
@Override
public HugeVertex readVertex(HugeGraph graph, BackendEntry backendEntry) {
E.checkNotNull(graph, "serializer graph");
if (backendEntry == null) {
return null;
}
TextBackendEntry entry = this.convertEntry(backendEntry);
// Parse label
String labelId = entry.column(this.formatSyspropName(HugeKeys.LABEL));
VertexLabel vertexLabel = VertexLabel.NONE;
if (labelId != null) {
vertexLabel = graph.vertexLabelOrNone(readId(labelId));
}
Id id = IdUtil.readString(entry.id().asString());
HugeVertex vertex = new HugeVertex(graph, id, vertexLabel);
String expiredTime = entry.column(this.formatSyspropName(HugeKeys.EXPIRED_TIME));
// Expired time is null when backend entry is fake vertex with edges
if (expiredTime != null) {
vertex.expiredTime(readLong(expiredTime));
}
// Parse all properties or edges of a Vertex
for (String name : entry.columnNames()) {
this.parseColumn(name, entry.column(name), vertex);
}
return vertex;
}
Aggregations