public void testAddIndexLabelWithSubIndex()

in hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/IndexLabelCoreTest.java [1030:1162]


    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");
    }