Search in sources :

Example 26 with VertexLabel

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

the class PersonalRankTraverser method getStartDirection.

private Directions getStartDirection(Id source, String label) {
    // NOTE: The outer layer needs to ensure that the vertex Id is valid
    HugeVertex vertex = (HugeVertex) graph().vertices(source).next();
    VertexLabel vertexLabel = vertex.schemaLabel();
    EdgeLabel edgeLabel = this.graph().edgeLabel(label);
    Id sourceLabel = edgeLabel.sourceLabel();
    Id targetLabel = edgeLabel.targetLabel();
    E.checkArgument(edgeLabel.linkWithLabel(vertexLabel.id()), "The vertex '%s' doesn't link with edge label '%s'", source, label);
    E.checkArgument(!sourceLabel.equals(targetLabel), "The edge label for personal rank must " + "link different vertex labels");
    if (sourceLabel.equals(vertexLabel.id())) {
        return Directions.OUT;
    } else {
        assert targetLabel.equals(vertexLabel.id());
        return Directions.IN;
    }
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) Id(com.baidu.hugegraph.backend.id.Id) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Example 27 with VertexLabel

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

the class MultiGraphsTest method testCopySchemaWithMultiGraphs.

@Test
public void testCopySchemaWithMultiGraphs() {
    List<HugeGraph> graphs = openGraphs("schema_g1", "schema_g2");
    for (HugeGraph graph : graphs) {
        graph.initBackend();
    }
    HugeGraph g1 = graphs.get(0);
    g1.serverStarted(IdGenerator.of("server-g2"), NodeRole.MASTER);
    HugeGraph g2 = graphs.get(1);
    g2.serverStarted(IdGenerator.of("server-g3"), NodeRole.MASTER);
    SchemaManager schema = g1.schema();
    schema.propertyKey("id").asInt().create();
    schema.propertyKey("name").asText().create();
    schema.propertyKey("age").asInt().valueSingle().create();
    schema.propertyKey("city").asText().create();
    schema.propertyKey("weight").asDouble().valueList().create();
    schema.propertyKey("born").asDate().ifNotExist().create();
    schema.propertyKey("time").asDate().ifNotExist().create();
    schema.vertexLabel("person").properties("id", "name", "age", "city", "weight", "born").primaryKeys("id").create();
    schema.vertexLabel("person2").properties("id", "name", "age", "city").primaryKeys("id").create();
    schema.edgeLabel("friend").sourceLabel("person").targetLabel("person").properties("time").create();
    schema.indexLabel("personByName").onV("person").secondary().by("name").create();
    schema.indexLabel("personByCity").onV("person").search().by("city").create();
    schema.indexLabel("personByAge").onV("person").range().by("age").create();
    schema.indexLabel("friendByTime").onE("friend").range().by("time").create();
    Assert.assertFalse(g2.existsPropertyKey("id"));
    Assert.assertFalse(g2.existsPropertyKey("name"));
    Assert.assertFalse(g2.existsPropertyKey("age"));
    Assert.assertFalse(g2.existsPropertyKey("city"));
    Assert.assertFalse(g2.existsPropertyKey("weight"));
    Assert.assertFalse(g2.existsPropertyKey("born"));
    Assert.assertFalse(g2.existsPropertyKey("time"));
    Assert.assertFalse(g2.existsVertexLabel("person"));
    Assert.assertFalse(g2.existsVertexLabel("person2"));
    Assert.assertFalse(g2.existsEdgeLabel("friend"));
    Assert.assertFalse(g2.existsIndexLabel("personByName"));
    Assert.assertFalse(g2.existsIndexLabel("personByCity"));
    Assert.assertFalse(g2.existsIndexLabel("personByAge"));
    Assert.assertFalse(g2.existsIndexLabel("friendByTime"));
    // Copy schema from g1 to g2
    g2.schema().copyFrom(g1.schema());
    Assert.assertTrue(g2.existsPropertyKey("id"));
    Assert.assertTrue(g2.existsPropertyKey("name"));
    Assert.assertTrue(g2.existsPropertyKey("age"));
    Assert.assertTrue(g2.existsPropertyKey("city"));
    Assert.assertTrue(g2.existsPropertyKey("weight"));
    Assert.assertTrue(g2.existsPropertyKey("born"));
    Assert.assertTrue(g2.existsPropertyKey("time"));
    Assert.assertTrue(g2.existsVertexLabel("person"));
    Assert.assertTrue(g2.existsVertexLabel("person2"));
    Assert.assertTrue(g2.existsEdgeLabel("friend"));
    Assert.assertTrue(g2.existsIndexLabel("personByName"));
    Assert.assertTrue(g2.existsIndexLabel("personByCity"));
    Assert.assertTrue(g2.existsIndexLabel("personByAge"));
    Assert.assertTrue(g2.existsIndexLabel("friendByTime"));
    for (PropertyKey copied : g2.schema().getPropertyKeys()) {
        PropertyKey origin = g1.schema().getPropertyKey(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    for (VertexLabel copied : schema.getVertexLabels()) {
        VertexLabel origin = g1.schema().getVertexLabel(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    for (EdgeLabel copied : schema.getEdgeLabels()) {
        EdgeLabel origin = g1.schema().getEdgeLabel(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    for (IndexLabel copied : schema.getIndexLabels()) {
        IndexLabel origin = g1.schema().getIndexLabel(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    // Copy schema again from g1 to g2 (ignore identical content)
    g2.schema().copyFrom(g1.schema());
    for (PropertyKey copied : g2.schema().getPropertyKeys()) {
        PropertyKey origin = g1.schema().getPropertyKey(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    for (VertexLabel copied : schema.getVertexLabels()) {
        VertexLabel origin = g1.schema().getVertexLabel(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    for (EdgeLabel copied : schema.getEdgeLabels()) {
        EdgeLabel origin = g1.schema().getEdgeLabel(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    for (IndexLabel copied : schema.getIndexLabels()) {
        IndexLabel origin = g1.schema().getIndexLabel(copied.name());
        Assert.assertTrue(origin.hasSameContent(copied));
    }
    for (HugeGraph graph : graphs) {
        graph.clearBackend();
    }
    destroyGraphs(graphs);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Test(org.junit.Test)

Example 28 with VertexLabel

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

the class IndexLabelCoreTest method testAddIndexLabelOfVertex.

@Test
public void testAddIndexLabelOfVertex() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.propertyKey("born").asDate().ifNotExist().create();
    schema.propertyKey("fans").asLong().ifNotExist().create();
    schema.propertyKey("height").asFloat().ifNotExist().create();
    schema.propertyKey("idNo").asText().ifNotExist().create();
    schema.propertyKey("category").asText().valueSet().ifNotExist().create();
    schema.propertyKey("score").asInt().valueSet().ifNotExist().create();
    schema.vertexLabel("person").properties("id", "name", "age", "city", "born", "tags", "category", "score", "fans", "height", "weight", "idNo").primaryKeys("id").create();
    schema.indexLabel("personByName").onV("person").secondary().by("name").create();
    schema.indexLabel("personByCity").onV("person").search().by("city").create();
    schema.indexLabel("personByAge").onV("person").range().by("age").create();
    schema.indexLabel("personByBorn").onV("person").range().by("born").create();
    schema.indexLabel("personByFans").onV("person").range().by("fans").create();
    schema.indexLabel("personByHeight").onV("person").range().by("height").create();
    schema.indexLabel("personByWeight").onV("person").range().by("weight").create();
    schema.indexLabel("personByIdNo").onV("person").unique().by("idNo").create();
    schema.indexLabel("personByTags").onV("person").secondary().by("tags").create();
    schema.indexLabel("personByCategory").onV("person").search().by("category").create();
    schema.indexLabel("personByScore").onV("person").secondary().by("score").create();
    VertexLabel person = schema.getVertexLabel("person");
    IndexLabel personByName = schema.getIndexLabel("personByName");
    IndexLabel personByCity = schema.getIndexLabel("personByCity");
    IndexLabel personByAge = schema.getIndexLabel("personByAge");
    IndexLabel personByBorn = schema.getIndexLabel("personByBorn");
    IndexLabel personByFans = schema.getIndexLabel("personByFans");
    IndexLabel personByHeight = schema.getIndexLabel("personByHeight");
    IndexLabel personByWeight = schema.getIndexLabel("personByWeight");
    IndexLabel personByIdNo = schema.getIndexLabel("personByIdNo");
    IndexLabel personByTags = schema.getIndexLabel("personByTags");
    IndexLabel personByCategory = schema.getIndexLabel("personByCategory");
    IndexLabel personByScore = schema.getIndexLabel("personByScore");
    Assert.assertNotNull(personByName);
    Assert.assertNotNull(personByCity);
    Assert.assertNotNull(personByAge);
    Assert.assertNotNull(personByBorn);
    Assert.assertNotNull(personByFans);
    Assert.assertNotNull(personByHeight);
    Assert.assertNotNull(personByWeight);
    Assert.assertNotNull(personByIdNo);
    Assert.assertNotNull(personByTags);
    Assert.assertNotNull(personByCategory);
    Assert.assertEquals(11, person.indexLabels().size());
    assertContainsIl(person.indexLabels(), "personByName", "personByCity", "personByAge", "personByBorn", "personByFans", "personByHeight", "personByWeight", "personByIdNo", "personByTags", "personByCategory", "personByScore");
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByName.baseType());
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByCity.baseType());
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByAge.baseType());
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByBorn.baseType());
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByFans.baseType());
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByHeight.baseType());
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByWeight.baseType());
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByIdNo.baseType());
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByTags.baseType());
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByCategory.baseType());
    Assert.assertEquals(HugeType.VERTEX_LABEL, personByScore.baseType());
    assertVLEqual("person", personByName.baseValue());
    assertVLEqual("person", personByCity.baseValue());
    assertVLEqual("person", personByAge.baseValue());
    assertVLEqual("person", personByBorn.baseValue());
    assertVLEqual("person", personByFans.baseValue());
    assertVLEqual("person", personByHeight.baseValue());
    assertVLEqual("person", personByWeight.baseValue());
    assertVLEqual("person", personByIdNo.baseValue());
    assertVLEqual("person", personByTags.baseValue());
    assertVLEqual("person", personByCategory.baseValue());
    assertVLEqual("person", personByScore.baseValue());
    Assert.assertEquals(IndexType.SECONDARY, personByName.indexType());
    Assert.assertEquals(IndexType.SEARCH, personByCity.indexType());
    Assert.assertEquals(IndexType.RANGE_INT, personByAge.indexType());
    Assert.assertEquals(IndexType.RANGE_LONG, personByBorn.indexType());
    Assert.assertEquals(IndexType.RANGE_LONG, personByFans.indexType());
    Assert.assertEquals(IndexType.RANGE_FLOAT, personByHeight.indexType());
    Assert.assertEquals(IndexType.RANGE_DOUBLE, personByWeight.indexType());
    Assert.assertEquals(IndexType.UNIQUE, personByIdNo.indexType());
    Assert.assertEquals(IndexType.SECONDARY, personByTags.indexType());
    Assert.assertEquals(IndexType.SEARCH, personByCategory.indexType());
    Assert.assertEquals(IndexType.SECONDARY, personByScore.indexType());
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 29 with VertexLabel

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

the class IndexLabelCoreTest method testRebuildIndexLabelOfVertex.

@Test
public void testRebuildIndexLabelOfVertex() {
    Assume.assumeTrue("Not support range condition query", storeFeatures().supportsQueryWithRangeCondition());
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
    schema.indexLabel("personByCity").onV("person").secondary().by("city").create();
    schema.indexLabel("personByAge").onV("person").range().by("age").create();
    VertexLabel person = schema.getVertexLabel("person");
    Assert.assertEquals(2, person.indexLabels().size());
    assertContainsIl(person.indexLabels(), "personByCity", "personByAge");
    graph().addVertex(T.label, "person", "name", "Baby", "city", "Hongkong", "age", 3);
    graph().tx().commit();
    Vertex vertex = graph().traversal().V().hasLabel("person").has("city", "Hongkong").next();
    Assert.assertNotNull(vertex);
    vertex = graph().traversal().V().hasLabel("person").has("age", P.inside(2, 4)).next();
    Assert.assertNotNull(vertex);
    schema.indexLabel("personByCity").rebuild();
    vertex = graph().traversal().V().hasLabel("person").has("city", "Hongkong").next();
    Assert.assertNotNull(vertex);
    schema.indexLabel("personByAge").rebuild();
    vertex = graph().traversal().V().hasLabel("person").has("age", P.inside(2, 4)).next();
    Assert.assertNotNull(vertex);
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 30 with VertexLabel

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

the class SchemaCoreTest method assertVLEqual.

protected void assertVLEqual(String label, Id id) {
    VertexLabel vertexLabel = graph().vertexLabel(label);
    Assert.assertEquals(id, vertexLabel.id());
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel)

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