All Grakn migrators extend the
AbstractMigrator class or implement the
Migrator interface. The migrators are a wrapper around the
LoaderClient and as such expose many of the same configuration options.
Each migrator may have a slightly different constructor (for example,
Json migration constructors accept the data file whereas
SQL migration accepts the SQL JDBC connection). They should all accept a template and a data accessor.
CSVMigrator migrator = new CSVMigrator(String template, File dataFile);
To migrate the provided data into a knowledge graph, call the
load function, providing the keyspace and location where Grakn Engine is running.
migrator.load(String uri, String keyspace);
Alternatively, the user can call a
load method with more configuration options. The configuration options are described in more detail on the loader client API page.
migrator.load(String uri, String keyspace, int batchSize, int numberActiveTasks, boolean retry)
Some migrators have a
close method that should be called after loading has completed. As the
load method blocks the calling thread, this is easily done. A quick example of JSON migration performed from java:
CSVMigrator migrator = new CSVMigrator("insert $x isa person has name <name>", new File("people.csv")); migrator.load(Grakn.DEFAULT_URI, "genealogy", 10, 10, false); migrator.close();
There is an example of using the Java Migration API for JSON data on the sample projects repository on Github.
There is an example of SQL migration using the Java API discussed on this portal.