Search in sources :

Example 76 with SchemaManager

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

the class IndexLabelCoreTest method testAddIndexLabelWithSameFieldsAndSameIndexType.

@Test
public void testAddIndexLabelWithSameFieldsAndSameIndexType() {
    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();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.indexLabel("personByCity1").onV("person").secondary().by("city").create();
    });
    schema.indexLabel("personByCitySearch").onV("person").search().by("city").create();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.indexLabel("personByCitySearch1").onV("person").search().by("city").create();
    });
    schema.indexLabel("personByAge").onV("person").range().by("age").create();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.indexLabel("personByAge1").onV("person").range().by("age").create();
    });
    schema.indexLabel("personByAgeAndCity").onV("person").secondary().by("age", "city").create();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.indexLabel("personByAgeAndCity1").onV("person").secondary().by("age", "city").create();
    });
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 77 with SchemaManager

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

the class IndexLabelCoreTest method testAddIndexLabelWithSubIndex.

@Test
public void testAddIndexLabelWithSubIndex() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    // Composite secondary index override prefix secondary index
    schema.vertexLabel("person").properties("name", "age", "city", "weight").create();
    schema.indexLabel("personByCity").onV("person").secondary().by("city").create();
    schema.getIndexLabel("personByCity");
    schema.indexLabel("personByCityAndName").onV("person").secondary().by("city", "name").create();
    Assert.assertThrows(NotFoundException.class, () -> {
        schema.getIndexLabel("personByCity");
    });
    schema.vertexLabel("person1").properties("name", "age", "city", "weight").create();
    schema.indexLabel("person1ByCity").onV("person1").secondary().by("city").create();
    schema.getIndexLabel("person1ByCity");
    schema.indexLabel("person1ByCityAndAge").onV("person1").secondary().by("city", "age").create();
    Assert.assertThrows(NotFoundException.class, () -> {
        schema.getIndexLabel("person1ByCity");
    });
    // Composite shard index override prefix shard index
    schema.vertexLabel("person2").properties("name", "age", "city", "weight").create();
    schema.indexLabel("person2ByCity").onV("person2").shard().by("city").create();
    schema.getIndexLabel("person2ByCity");
    schema.indexLabel("person2ByCityAndName").onV("person2").shard().by("city", "name").create();
    Assert.assertThrows(NotFoundException.class, () -> {
        schema.getIndexLabel("person2ByCity");
    });
    schema.vertexLabel("person3").properties("name", "age", "city", "weight").create();
    schema.indexLabel("person3ByCity").onV("person3").shard().by("city").create();
    schema.getIndexLabel("person3ByCity");
    schema.indexLabel("person3ByCityAndAge").onV("person3").shard().by("city", "age").create();
    Assert.assertThrows(NotFoundException.class, () -> {
        schema.getIndexLabel("person3ByCity");
    });
    // Composite shard index override prefix secondary index
    schema.vertexLabel("person4").properties("name", "age", "city", "weight").create();
    schema.indexLabel("person4ByCity").onV("person4").secondary().by("city").create();
    schema.getIndexLabel("person4ByCity");
    schema.indexLabel("person4ByCityAndName").onV("person4").shard().by("city", "name").create();
    Assert.assertThrows(NotFoundException.class, () -> {
        schema.getIndexLabel("person4ByCity");
    });
    // Composite secondary index override prefix all string shard index
    schema.vertexLabel("person5").properties("name", "age", "city", "weight").create();
    schema.indexLabel("person5ByCity").onV("person5").shard().by("city").create();
    schema.getIndexLabel("person5ByCity");
    schema.indexLabel("person5ByCityAndAge").onV("person5").secondary().by("city", "age").create();
    Assert.assertThrows(NotFoundException.class, () -> {
        schema.getIndexLabel("person5ByCity");
    });
    // Range index override secondary index
    schema.vertexLabel("person6").properties("name", "age", "city", "weight").create();
    schema.indexLabel("person6ByAge").onV("person6").secondary().by("age").create();
    schema.getIndexLabel("person6ByAge");
    schema.indexLabel("person6ByAge1").onV("person6").range().by("age").create();
    Assert.assertThrows(NotFoundException.class, () -> {
        schema.getIndexLabel("person6ByAge");
    });
    // Range index override shard index
    schema.vertexLabel("person7").properties("name", "age", "city", "weight").create();
    schema.indexLabel("person7ByAge").onV("person7").shard().by("age").create();
    schema.getIndexLabel("person7ByAge");
    schema.indexLabel("person7ByAge1").onV("person7").range().by("age").create();
    Assert.assertThrows(NotFoundException.class, () -> {
        schema.getIndexLabel("person7ByAge");
    });
    // Unique index override more fields unique index
    schema.vertexLabel("person8").properties("name", "age", "city", "weight").create();
    schema.indexLabel("person8ByCityAndAge").onV("person8").unique().by("city", "age").create();
    schema.getIndexLabel("person8ByCityAndAge");
    schema.indexLabel("person8ByAge").onV("person8").unique().by("age").create();
    Assert.assertThrows(NotFoundException.class, () -> {
        schema.getIndexLabel("person8ByCityAndAge");
    });
    schema.getIndexLabel("person8ByAge");
    schema.vertexLabel("person9").properties("name", "age", "city", "weight").create();
    schema.indexLabel("person9ByCityAndAge").onV("person9").unique().by("city", "age").create();
    schema.getIndexLabel("person9ByCityAndAge");
    schema.indexLabel("person9ByCity").onV("person9").unique().by("city").create();
    Assert.assertThrows(NotFoundException.class, () -> {
        schema.getIndexLabel("person9ByCityAndAge");
    });
    schema.getIndexLabel("person9ByCity");
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 78 with SchemaManager

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

the class IndexLabelCoreTest method testAddIndexLabelWithIllegalName.

@Test
public void testAddIndexLabelWithIllegalName() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
    // Empty string
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.indexLabel("").onV("person").by("name").create();
    });
    // One space
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.indexLabel(" ").onV("person").by("name").create();
    });
    // Two spaces
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.indexLabel("  ").onV("person").by("name").create();
    });
    // Multi spaces
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.indexLabel("    ").onV("person").by("name").create();
    });
    // Start with '~'
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.indexLabel("~").onV("person").by("name").create();
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.indexLabel("~ ").onV("person").by("name").create();
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.indexLabel("~x").onV("person").by("name").create();
    });
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 79 with SchemaManager

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

the class IndexLabelCoreTest method testDuplicateIndexLabelWithIdentityProperties.

@Test
public void testDuplicateIndexLabelWithIdentityProperties() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
    schema.indexLabel("index4Person").onV("person").by("age", "city").secondary().ifNotExist().create();
    schema.indexLabel("index4Person").onV("person").by("age", "city").secondary().checkExist(false).create();
    schema.indexLabel("index4Person").onV("person").by("age", "city").ifNotExist().create();
    schema.indexLabel("ageIndex4Person").onV("person").by("age").range().ifNotExist().create();
    schema.indexLabel("ageIndex4Person").onV("person").by("age").range().checkExist(false).create();
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 80 with SchemaManager

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

the class IndexLabelCoreTest method testAddIndexLabelWithSameFieldsBetweenSearchSecondary.

@Test
public void testAddIndexLabelWithSameFieldsBetweenSearchSecondary() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
    schema.indexLabel("personByCity").onV("person").search().by("city").create();
    schema.indexLabel("personByCity2").onV("person").secondary().by("city").create();
}
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