use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class VertexLabelCoreTest method testAddVertexLabelWithoutPKStrategyButCallPrimaryKey.
@Test
public void testAddVertexLabelWithoutPKStrategyButCallPrimaryKey() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.vertexLabel("person").useAutomaticId().primaryKeys("name").properties("name", "age", "city").create();
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.vertexLabel("person").useCustomizeStringId().primaryKeys("name").properties("name", "age", "city").create();
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.vertexLabel("person").useCustomizeNumberId().primaryKeys("name").properties("name", "age", "city").create();
});
}
use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class VertexLabelCoreTest method testAppendVertexLabelWithNonNullProperties.
@Test
public void testAppendVertexLabelWithNonNullProperties() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
schema.vertexLabel("person").properties("name", "age").primaryKeys("name").create();
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.vertexLabel("person").properties("city").append();
});
}
use of com.baidu.hugegraph.schema.SchemaManager 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());
}
use of com.baidu.hugegraph.schema.SchemaManager 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);
}
use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class IndexLabelCoreTest method testAppendIndexLabelWithUserdata.
@Test
public void testAppendIndexLabelWithUserdata() {
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).create();
Assert.assertEquals(2, personByName.userdata().size());
Assert.assertEquals(0, personByName.userdata().get("min"));
personByName = schema.indexLabel("personByName").userdata("min", 1).userdata("max", 100).append();
Assert.assertEquals(3, personByName.userdata().size());
Assert.assertEquals(1, personByName.userdata().get("min"));
Assert.assertEquals(100, personByName.userdata().get("max"));
}
Aggregations