GraphSONデータの読み込み
DSE Graph Loaderを使用してGraphSONデータを読み込む方法。
GraphSONデータのデータ・マッピング・スクリプトを説明付きで示します。スクリプト全文は、ページの最後にあります。
        注: DSE Graph Loaderでは、DSE GraphまたはApache TinkerGraphで生成されたGraphSONファイル、すなわち、Apache TinkerPopに含まれているインメモリー・グラフ・データベースを読み込むことができます。
手順
- 必要に応じて、マッピング・スクリプトに構成を追加します。
- 
                データ入力ファイルを指定します。変数inputfiledirは、入力ファイルのディレクトリーを指定します。指定されたファイルは、読み込みで使用されます。
 GraphSON入力ファイルがDSE Graphから生成される場合、追加手順// 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()によって、入力データをストリーミングできるため、大きなファイルの転送が容易になります。// 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()
- 
                ファイルをjsonファイルとして指定し、追加手順graphson()によって、このファイルをGraphSONファイルとして処理する必要があることが識別されます。マップrecipeInputが作成され、データの処理に使用されます。recipeInput = Graph.file(inputfiledir + 'recipe.json')File.csvまたはFile.jsonとは対照的に、Graph.fileが使用されることに注意してください。
- マッピング・スクリプトの本文を作成します。マッピング・スクリプトのこの部分は、ファイル形式に関係なく同じです。ただし、GraphSONファイルではわずかに変更されたバージョンが使用されます。
- 
                GraphSONの読み込みに、DSE Graph Loaderをdry runとして実行するには、次のコマンドを使用します。
                graphloader recipeMappingGraphSON.groovy -graph testGraphSON -address localhost -dryrun true テスト目的の場合、 graphloaderの実行前に、指定されたグラフが存在する必要はありません。ただし、プロダクション・アプリケーションの場合は、グラフとスキーマを作成してから、graphloaderを使用する必要があります。
- 
                読み込みスクリプトの全文は次のようになります。
                /* 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" } }
