Scenario: Writing information of actors and movies to Neo4j with hierarchical relationship - 6.3

Talend Open Studio for Big Data Components Reference Guide

EnrichVersion
6.3
EnrichProdName
Talend Open Studio for Big Data
task
Data Governance
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

This scenario describes a Job that will import information about actors and movies from two CSV files into a remote Neo4j database and then create relationship between the actors and the movies based on another CSV file that describes the actors' roles in the movies.

Adding and linking components

  1. Create a Job and add the following components to the Job by typing theirs names in the design workspace or dropping them from the Palette:

    • a tNeo4jConnection component, to open a connection to a Neo4j database,

    • three tFileInputDelimited components, to read the input information of actors and movies,

    • two tNeo4jOutput components, to write information of movies and actors to the connected Neo4j database,

    • a tNeo4jOutputRelationship component, to create relationship between actors and movies, and

    • a tNeo4jClose component, to close the previous opened Neo4j connection at the end of Job execution.

  2. Link the first tFileInputDelimited to the first tNeo4jOutput component using a Row > Main connection. This sub-job will import the actors data into the Neo4j database.

  3. Link the second tFileInputDelimited component to the second tNeo4jOutput component using a Row > Main connection. This sub-job will import the movies data into the Neo4j database.

  4. Link the third tFileInputDelimited component to the tNeo4jOutputRelationship component using a Row > Main connection. This sub-job will create relationship between actors and movies.

  5. Link the sub-jobs using Trigger > On Subjob Ok connections.

  6. Label the components to better identify their roles in the Job.

Configuring the components

Opening a Neo4j database connection

  1. Double-click the tNeo4jConnection component to open its Basic settings view on the Component tab.

  2. From the DB Version list, select Neo4J 2.X.X to enable node labeling.

  3. Select the Use a remote server check box and specify the URL of the Neo4j server in the Server URL field, "http://localhost:7474/db/data" in this example.

Importing the actors data into Neo4j

  1. Double-click the first tFileInputDelimited component to open its Basic settings view on the Component tab.

  2. In the File name/Stream field, specify the path to the CSV file that describes the actors' names, the years they were born in, and their roles in the movies.

    The input CSV file used in this example is as follows:

    Name;Born
    Keanu Reeves;1964
    Laurence Fishburne;1961
    Carrie-Anne Moss;1967
  3. In the Header field, specify the number of rows to skip as header rows. In this example, the first row of the CSV file is the header row.

  4. Click the [...] button next to Edit schema to open the [Schema] dialog box, and define the input schema based on the structure of the input file. In this example, the input schema is composed of two columns, name and born, both of type String.

    When done, click OK to close the [Schema] dialog box and propagate the schema to the next component.

  5. Click the first tNeo4jOutput component and select the Component tab to open its Basic settings view.

  6. Select the Use an existing connection check box to reuse the Neo4j database connection opened by the tNeo4jConnection component, which is the only connection component used in this example.

  7. Double-click the tNeo4jOutput component or click the Mapping button on the component's Basic settings view to open the index and relationship mapping editor.

  8. With the name column selected from the schema panel, click the Index creation tab, click the [+] button to add a row in the table, and create an index named name on this column:

    • In the Name field, enter name between double quotation marks.

    • In the Key field, enter name between double quotation marks to give the index a key name.

    Then click in the schema panel to validate your index creation, and click OK to close the mapping editor.

  9. Select the Use label (Neo4j > 2.0) check box and enter Actors between double quotation marks in the Label name field so that the nodes to be created will be labeled Actors.

Importing the movies data into Neo4j

  1. Double-click the second tFileInputDelimited component to open its Basic settings view on the Component tab.

  2. In the File name/Stream field, specify the path to the CSV file that contains the information of the movies.

    The input CSV file used in this example is as follows:

    Title;Released;Tagline
    The Matrix;03-31-1999;Welcome to the Real World
    The Matrix Reloaded;05-07-2003;Free Your Mind
    The Matrix Revolutions;10-27-2003;Everything that has a Beginning has an End
  3. In the Header field, specify the number of rows to skip as header rows. In this example, the first row of the CSV file is the header row.

  4. Click the [...] button next to Edit schema to open the [Schema] dialog box, and define the input schema based on the structure of the input file. In this example, the input schema is composed of three columns, title (type String), released (type Date), and tagline (type String).

    When done, click OK to close the [Schema] dialog box and propagate the schema to the next component.

  5. Click the second tNeo4jOutput component and select the Component tab to open its Basic settings view.