use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.
the class FileLoadTest method testClearSchemaBeforeLoad.
@Test
public void testClearSchemaBeforeLoad() {
LoadOptions options = new LoadOptions();
options.host = Constants.HTTP_PREFIX + SERVER;
options.port = PORT;
options.graph = GRAPH;
HugeClient client = HugeClientHolder.create(options);
SchemaManager schema = client.schema();
schema.propertyKey("name").asText().ifNotExist().create();
schema.propertyKey("age").asInt().ifNotExist().create();
// The old datatype of city is int
schema.propertyKey("city").asInt().ifNotExist().create();
schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").ifNotExist().create();
// Actual city datatype is String
ioUtil.write("vertex_person.csv", "name,age,city", "marko,29,Beijing", "vadas,27,Hongkong", "josh,32,Beijing", "peter,35,Shanghai", "\"li,nary\",26,\"Wu,han\"");
String[] args1 = new String[] { "-f", structPath("clear_schema_before_load/struct.json"), "-g", GRAPH, "-h", SERVER, "--batch-insert-threads", "2", "--test-mode", "true" };
Assert.assertThrows(ParseException.class, () -> {
HugeGraphLoader.main(args1);
}, (e) -> {
String msg = e.getMessage();
Assert.assertTrue(msg.startsWith("Failed to convert value"));
Assert.assertTrue(msg.endsWith("to Number"));
});
String[] args2 = new String[] { "-f", structPath("clear_schema_before_load/struct.json"), "-s", configPath("clear_schema_before_load/schema.groovy"), "-g", GRAPH, "-h", SERVER, "--clear-all-data", "true", "--batch-insert-threads", "2", "--test-mode", "true" };
HugeGraphLoader.main(args2);
List<Vertex> vertices = CLIENT.graph().listVertices();
Assert.assertEquals(5, vertices.size());
client.close();
}
Aggregations