Loading GraphSON data
How to use the DSE Graph Loader to load GraphSON data.
The data mapping script for GraphSON data is shown with explanation. The full script
is found at the bottom of the page.
Note: DSE Graph Loader can load GraphSON files
generated with DSE Graph or Apache TinkerGraph, the in-memory
graph database included with Apache TinkerPop.
Procedure
- If desired, add configuration to the mapping script.
-
Specify the data input file. The variable
inputfiledir
specifies the directory for the input file. The identified file will be used for loading.
If the GraphSON input file is generated from DSE Graph, an additional step// DATA INPUT // Define the data input source // inputfiledir is the directory for the input files inputfiledir = '/tmp/GraphSON/' recipeInput = Graph.file(inputfiledir + 'recipe.json').graphson()
dse()
will allow the input data to be streamed, facilitating large file transfers.// DATA INPUT // Define the data input source // inputfiledir is the directory for the input files inputfiledir = '/tmp/GraphSON/' recipeInput = Graph.file(inputfiledir + 'recipe.json').graphson().dse()
-
The file is specified as a
json
file and an additional stepgraphson()
identifies that the file should be processed as a GraphSON file. A map,recipeInput
, is created that will be used to process the data.recipeInput = Graph.file(inputfiledir + 'recipe.json')
Note that
Graph.file
is used, in contrast toFile.csv
orFile.json
. - Create the main body of the mapping script. This part of the mapping script is the same regardless of the file format, although GraphSON files use a slightly modified version.
-
To run DSE Graph Loader for GraphSON loading as a dry run, use the following
command:
graphloader recipeMappingGraphSON.groovy -graph testGraphSON -address localhost -dryrun true
For testing purposes, the graph specified does not have to exist prior to running
graphloader
. However, for production applications, the graph and schema should be created prior to usinggraphloader
. -
The full loading script is shown:
/* SAMPLE INPUT GraphSON file is a JSON-like file */ // CONFIGURATION // Configures the data loader to create the schema config create_schema: true, load_new: true // DATA INPUT // Define the data input source // inputfiledir is the directory for the input files inputfiledir = '/tmp/GraphSON/' recipeInput = Graph.file(inputfiledir + 'recipe.json').graphson() //Specifies what data source to load using which mapper (as defined inline) load(recipeInput.vertices()).asVertices { labelField "~label" key "~id", "id" } load(recipeInput.edges()).asEdges { labelField "~label" outV "outV", { labelField "~label" key "~id", "id" } inV "inV", { labelField "~label" key "~id", "id" } }