use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class VertexCoreTest method testQueryByUnionIndexInPageWithSomeIndexNoData.
@Test
public void testQueryByUnionIndexInPageWithSomeIndexNoData() {
Assume.assumeTrue("Not support paging", storeFeatures().supportsQueryByPage());
HugeGraph graph = graph();
SchemaManager schema = graph.schema();
GraphTraversalSource g = graph.traversal();
initPageTestData();
// Author has index by name but no data
schema.indexLabel("authorByName").onV("author").by("name").secondary().ifNotExist().create();
GraphTraversal<Vertex, Vertex> iter = g.V().has("name", "marko").has("~page", "").limit(1);
Assert.assertEquals(1, IteratorUtils.count(iter));
String page = TraversalUtil.page(iter);
List<Vertex> vertices;
vertices = g.V().has("name", "marko").has("~page", page).limit(1).toList();
Assert.assertEquals(1, vertices.size());
Vertex vertex1 = vertices.get(0);
vertices = g.V().has("name", "marko").has("~page", page).limit(9).toList();
Assert.assertEquals(9, vertices.size());
Assert.assertTrue(vertices.contains(vertex1));
vertices = g.V().has("name", "marko").has("~page", page).limit(18).toList();
Assert.assertEquals(18, vertices.size());
Vertex vertex3 = vertices.get(17);
vertices = g.V().has("name", "marko").has("~page", page).limit(40).toList();
Assert.assertEquals(33, vertices.size());
Assert.assertTrue(vertices.contains(vertex3));
}
use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class VertexCoreTest method testAddVertexWithAutomaticIdStrategy.
@Test
public void testAddVertexWithAutomaticIdStrategy() {
HugeGraph graph = graph();
SchemaManager schema = graph.schema();
// May be set forceString=true by config
Whitebox.setInternalState(SnowflakeIdGenerator.instance(graph), "forceString", false);
schema.vertexLabel("programmer").useAutomaticId().properties("name", "age", "city").create();
Vertex v1 = graph.addVertex(T.label, "programmer", "name", "marko", "age", 18, "city", "Beijing");
this.mayCommitTx();
List<Vertex> vertices = graph.traversal().V().toList();
Assert.assertEquals(1, vertices.size());
assertContains(vertices, T.label, "programmer", "name", "marko", "age", 18, "city", "Beijing");
Vertex v2 = graph.addVertex(T.label, "programmer", "name", "marko", "age", 18, "city", "Beijing");
this.mayCommitTx();
Assert.assertNotEquals(v1.id(), v2.id());
vertices = graph.traversal().V().toList();
Assert.assertEquals(2, vertices.size());
vertices = graph.traversal().V(v2.id()).toList();
Assert.assertEquals(1, vertices.size());
assertContains(vertices, T.label, "programmer", "name", "marko", "age", 18, "city", "Beijing");
}
use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class HugeGraphAuthProxy method schema.
@Override
public SchemaManager schema() {
SchemaManager schema = this.hugegraph.schema();
schema.proxy(this);
return schema;
}
use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class TestGraph method initClassicSchema.
@Watched
public void initClassicSchema(IdStrategy idStrategy) {
SchemaManager schema = this.graph.schema();
schema.propertyKey("id").asInt().ifNotExist().create();
schema.propertyKey("weight").asFloat().ifNotExist().create();
schema.propertyKey("name").ifNotExist().create();
schema.propertyKey("lang").ifNotExist().create();
schema.propertyKey("age").asInt().ifNotExist().create();
switch(idStrategy) {
case AUTOMATIC:
schema.vertexLabel("vertex").properties("id", "name", "age", "lang").nullableKeys("id", "name", "age", "lang").ifNotExist().create();
break;
case CUSTOMIZE_STRING:
schema.vertexLabel("vertex").properties("id", "name", "age", "lang").nullableKeys("id", "name", "age", "lang").useCustomizeStringId().ifNotExist().create();
break;
default:
throw new AssertionError(String.format("Id strategy must be customize or automatic"));
}
schema.edgeLabel("knows").link("vertex", "vertex").properties("weight").nullableKeys("weight").ifNotExist().create();
schema.edgeLabel("created").link("vertex", "vertex").properties("weight").nullableKeys("weight").ifNotExist().create();
schema.indexLabel("vertexByName").onV("vertex").by("name").secondary().ifNotExist().create();
schema.indexLabel("vertexByAge").onV("vertex").by("age").range().ifNotExist().create();
}
use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class TestGraph method initEdgeLabelPersonKnowsPerson.
public void initEdgeLabelPersonKnowsPerson() {
SchemaManager schema = this.graph.schema();
schema.edgeLabel("knows").link("person", "person").properties("weight").nullableKeys("weight").ifNotExist().create();
}
Aggregations