Search in sources :

Example 21 with VertexLabel

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());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 22 with VertexLabel

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;
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) IdStrategy(com.baidu.hugegraph.type.define.IdStrategy) SchemaStatus(com.baidu.hugegraph.type.define.SchemaStatus)

Example 23 with 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;
}
Also used : 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)

Example 24 with VertexLabel

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;
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) IdStrategy(com.baidu.hugegraph.type.define.IdStrategy) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) SchemaStatus(com.baidu.hugegraph.type.define.SchemaStatus)

Example 25 with 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;
}
Also used : 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)

Aggregations

VertexLabel (com.baidu.hugegraph.schema.VertexLabel)86 Test (org.junit.Test)35 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)27 Id (com.baidu.hugegraph.backend.id.Id)23 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)20 HugeGraph (com.baidu.hugegraph.HugeGraph)19 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)19 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)12 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)12 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)11 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)7 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)6 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)5 Timed (com.codahale.metrics.annotation.Timed)5 RolesAllowed (jakarta.annotation.security.RolesAllowed)5 Produces (jakarta.ws.rs.Produces)5 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)4 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)4 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)4 Date (java.util.Date)4