Search in sources :

Example 71 with SchemaManager

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

the class IndexLabelCoreTest method testEliminateIndexLabelWithUserdata.

@Test
public void testEliminateIndexLabelWithUserdata() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("id", "name", "age", "city").primaryKeys("id").create();
    IndexLabel personByName = schema.indexLabel("personByName").onV("person").secondary().by("name").userdata("min", 0).userdata("max", 100).create();
    Assert.assertEquals(3, personByName.userdata().size());
    Assert.assertEquals(0, personByName.userdata().get("min"));
    Assert.assertEquals(100, personByName.userdata().get("max"));
    personByName = schema.indexLabel("personByName").userdata("max", "").eliminate();
    Assert.assertEquals(2, personByName.userdata().size());
    Assert.assertEquals(0, personByName.userdata().get("min"));
}
Also used : IndexLabel(com.baidu.hugegraph.schema.IndexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 72 with SchemaManager

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

the class IndexLabelCoreTest method testDuplicateIndexLabelWithDifferentProperties.

@Test
public void testDuplicateIndexLabelWithDifferentProperties() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
    schema.edgeLabel("friend").link("person", "person").properties("time").ifNotExist().create();
    schema.indexLabel("index4Person").onV("person").by("age", "city").secondary().ifNotExist().create();
    Assert.assertThrows(ExistedException.class, () -> {
        schema.indexLabel("index4Person").onV("person").by(// remove city
        "age").secondary().checkExist(false).create();
    });
    Assert.assertThrows(ExistedException.class, () -> {
        schema.indexLabel("index4Person").onE(// not on person
        "friend").by("age").secondary().checkExist(false).create();
    });
    schema.indexLabel("index4Friend").onE("friend").search().by("time").ifNotExist().create();
    Assert.assertThrows(ExistedException.class, () -> {
        schema.indexLabel("index4Friend").onE("friend").by("time").checkExist(false).create();
    });
    schema.indexLabel("ageIndex4Person").onV("person").by("age").range().ifNotExist().create();
    Assert.assertThrows(ExistedException.class, () -> {
        schema.indexLabel("ageIndex4Person").onV("person").by("age").secondary().ifNotExist().create();
    });
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 73 with SchemaManager

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

the class IndexLabelCoreTest method testRemoveIndexLabelOfEdge.

@Test
public void testRemoveIndexLabelOfEdge() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("author").properties("id", "name").primaryKeys("id").create();
    schema.vertexLabel("book").properties("name").primaryKeys("name").create();
    schema.edgeLabel("authored").singleTime().link("author", "book").properties("contribution").create();
    Vertex james = graph().addVertex(T.label, "author", "id", 1, "name", "James Gosling");
    Vertex java1 = graph().addVertex(T.label, "book", "name", "java-1");
    schema.indexLabel("authoredByContri").onE("authored").secondary().by("contribution").create();
    EdgeLabel authored = schema.getEdgeLabel("authored");
    Assert.assertEquals(1, authored.indexLabels().size());
    assertContainsIl(authored.indexLabels(), "authoredByContri");
    james.addEdge("authored", java1, "contribution", "test");
    graph().tx().commit();
    Edge edge = graph().traversal().E().hasLabel("authored").has("contribution", "test").next();
    Assert.assertNotNull(edge);
    schema.indexLabel("authoredByContri").remove();
    Assert.assertThrows(NotFoundException.class, () -> {
        schema.getIndexLabel("authoredByContri");
    });
    /*
         * Should not expect that schemalabel previously constructed can be
         * dynamically modified with index label operation
         */
    authored = schema.getEdgeLabel("authored");
    Assert.assertEquals(0, authored.indexLabels().size());
    Assert.assertThrows(NoIndexException.class, () -> {
        graph().traversal().E().hasLabel("authored").has("contribution", "test").next();
    });
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Test(org.junit.Test)

Example 74 with SchemaManager

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

the class IndexLabelCoreTest method testAddIndexLabelWithInvalidFieldsForAggregateProperty.

@Test
public void testAddIndexLabelWithInvalidFieldsForAggregateProperty() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.propertyKey("sumProp").asLong().valueSingle().calcSum().ifNotExist().create();
    schema.vertexLabel("author").properties("id", "name", "age", "sumProp").primaryKeys("id").create();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.indexLabel("authorBySumProp").onV("author").by("sumProp").secondary().ifNotExist().create();
    }, e -> {
        Assert.assertContains("The aggregate type SUM is not indexable", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.indexLabel("authorBySumProp").onV("author").by("sumProp").range().ifNotExist().create();
    }, e -> {
        Assert.assertContains("The aggregate type SUM is not indexable", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.indexLabel("authorBySumProp").onV("author").by("sumProp").shard().ifNotExist().create();
    }, e -> {
        Assert.assertContains("The aggregate type SUM is not indexable", e.getMessage());
    });
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 75 with SchemaManager

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

the class IndexLabelCoreTest method testUpdateIndexLabelWithoutUserdata.

@Test
public void testUpdateIndexLabelWithoutUserdata() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("id", "name", "age", "city").primaryKeys("id").create();
    schema.vertexLabel("software").properties("id", "name").primaryKeys("id").create();
    schema.indexLabel("personByName").onV("person").secondary().by("name").userdata("min", 0).userdata("max", 100).create();
    Assert.assertThrows(HugeException.class, () -> {
        schema.indexLabel("personByName").onV("software").append();
    });
    Assert.assertThrows(HugeException.class, () -> {
        schema.indexLabel("personByName").range().append();
    });
    Assert.assertThrows(HugeException.class, () -> {
        schema.indexLabel("personByName").by("age").append();
    });
    Assert.assertThrows(HugeException.class, () -> {
        schema.indexLabel("personByName").onV("software").eliminate();
    });
    Assert.assertThrows(HugeException.class, () -> {
        schema.indexLabel("personByName").range().eliminate();
    });
    Assert.assertThrows(HugeException.class, () -> {
        schema.indexLabel("personByName").by("age").eliminate();
    });
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Aggregations

SchemaManager (com.baidu.hugegraph.schema.SchemaManager)261 Test (org.junit.Test)227 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)90 HugeGraph (com.baidu.hugegraph.HugeGraph)76 FakeVertex (com.baidu.hugegraph.testutil.FakeObjects.FakeVertex)40 Edge (org.apache.tinkerpop.gremlin.structure.Edge)30 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)27 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)22 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)20 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)19 FakeEdge (com.baidu.hugegraph.testutil.FakeObjects.FakeEdge)19 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)15 Id (com.baidu.hugegraph.backend.id.Id)12 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)8 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)7 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)7 Date (java.util.Date)6 Before (org.junit.Before)6 HashSet (java.util.HashSet)3 HugeException (com.baidu.hugegraph.HugeException)2