tNeo4jRow
Executes the stated Cypher query onto the specified Neo4J database.
Depending on the nature of the query, tNeo4jRow acts on the
data (although without handling data).
tNeo4jRow is the specific component for Neo4J database query. It
implements a flow in the Job design although it doesn’t provide output.
tNeo4jRow Standard properties
These properties are used to configure tNeo4jRow running in the Standard Job framework.
The Standard
tNeo4jRow component belongs to the Big Data and the Databases NoSQL families.
The component in this framework is available in all Talend products with Big Data
and in Talend Data Fabric.
Basic settings
Use an existing connection |
Select this check box and in the Component List click the relevant connection component to |
DB version |
Select the Neo4j version you are using. When you are using Neo4j version 3.2.X, this component works Do Neo4j version 2.X.X is compatible only with Java 7 or higher but it offers This list is not shown if the Use an Upon selecting a database version, you will be |
Remote server |
Select this check box if you use a Neo4j remote server, and specify the root URL in the Server URL field.
This check box appears only if you do not select the Use an existing connection check box and you are not using Neo4j V3.2.X. With V3.2.X, this component supports the remote mode only. |
Database path |
If you use Neo4j in embedded mode, specify the directory This field appears only if you do not select the |
Shutdown after |
Select this check box to shutdown the Neo4j database connection when no more Alternatively, you can use tNeo4jClose to shutdown the This avoids errors such as “Id file not properly shutdown” at next execution This check box is available only if the Use an existing |
Schema and Edit schema |
A schema is a row description. It defines the number of fields Click Edit
|
 |
Built-In: You create and store the schema locally for this component |
 |
Repository: You have already created the schema and stored it in the When the schema to be reused has default values that are You can find more details about how to |
Query |
Enter your Cypher query in double quotes. If you have |
Parameters |
Click the [+]
|
Die on error |
This check box is selected by default. Clear the check |
Advanced settings
tStatCatcher Statistics |
Select this check box to gather the Job processing metadata at the |
Commit every |
Enter the number of rows to be completed before committing batches This option is only supported by the embedded mode of the |
Global Variables
Global Variables |
NB_NODE_INSERTED: the number of nodes inserted. This is
NB_RELATIONSHIP_INSERTED: the number of relationships
NB_PROPERTY_UPDATED: the number of properties updated.
NB_NODE_DELETED: the number of nodes deleted. This is an
NB_RELATIONSHIP_DELETED: the number of relationships
ERROR_MESSAGE: the error message generated by the A Flow variable functions during the execution of a component while an After variable To fill up a field or expression with a variable, press Ctrl + For further information about variables, see |
Usage
Usage rule |
This component can be used as a standalone component or as an output component in a process. |
Limitation | n/a |
Creating nodes with a label using a Cypher query
This scenario applies only to Talend products with Big Data.
This scenario describes a Job that creates nodes with a label in an embedded Neo4j
database using a Cypher query, and then displays some properties of the specified node
on the console.
Adding and linking components
-
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, -
a tNeo4jRow component, to create
nodes in the Neo4j database with a Cypher query, -
a tNeo4jIntput component, to read
the specified properties of the created nodes, -
a tLogRow component, to display
the data on the Run console,
and -
a tNeo4jClose component, to close
the Neo4j database connection established by the tNeo4jConnection component.
-
-
Link the tNeo4jConnection component to
the tNeo4jRow component using a Trigger > On Subjob
Ok connection. -
Link the tNeo4jRow component to the
tNeo4jIntput component using a
Trigger > On
Subjob Ok connection. -
Link the tNeo4jIntput component to the
tLogRow component using a Row > Main
connection. -
Link the tNeo4jIntput component to the
tNeo4jClose component using a Trigger > On Subjob
Ok connection.
Configuring the components
Configuring a Neo4j database connection and nodes creation
-
Double-click the tNeo4jConnection
component to open its Basic settings view
on the Component tab. -
From the DB Version list, select
Neo4J 2.X.X to enable node labeling
support. -
In the Database path field, specify the
directory for your data files, “E:/Talend/DB/Neo4j/data” in this example.In this example, you will use Neo4j in embedded mode; to connect to a
remote Neo4j server via REST, click the Use a remote
server check box and specify the URL of the Neo4j
server. -
Double-click the tNeo4jRow component to
open its Basic settings view on the
Component tab. -
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. -
In the Query field, type in the Cypher
query to be executed by the component.In this example, type in the following query to create two nodes with the
label Managers and three properties –
id, name, and position:12"CREATE (a:Managers { id: 1, name: 'Gerald White', position: 'HR directory'})CREATE (b:Managers { id: 2, name: 'Jimmy Black', position: 'Sales manager'})"As this component does not have an input flow, leave the schema and the
parameter settings blank.
Configuring data retrieving and display
-
Double-click the tNeo4jInput component to
open its Basic settings view. -
Select the Use an existing connection
check box to reuse the connection opened by the tNeo4jConnection component. -
Click the […] button next to Edit schema and define the schema corresponding
to the node properties you want to retrieve and display. In this example,
the schema is composed of two columns, name and position, both
of type String.When done, click OK to close the
Schema dialog box and propagate the
schema to the next component.The defined schema columns automatically appear in the Mapping table. -
In the Query field, type in the Cypher
query to match the data to read from the Neo4j database. In this example,
use the following Cypher query to find the name and position of the manager
whose ID is 2.1"MATCH (ee:Managers{id:2}) RETURN ee.name, ee.position;"or1"MATCH (ee:Managers) WHERE ee.id = 2 RETURN ee.name, ee.position;" -
Fill the Return parameter field for each
schema column with a return parameter in double quotes to map the node
properties in the Neo4j database with the schema columns. -
Double-click the tLogRow component to
open its Basic settings view, and select
the Table (print values in cells of a
table) option to display the retrieved information in a
table.
Executing the Job
- Press Ctrl+S to save the Job.
-
Press F6 or click Run on the Run tab to run
the Job.Two nodes are created in the Neo4j database based on the Cypher query,
with the data files written in the specified directory, and the defined
information is retrieved and displayed on the console.
Importing data from a CSV file to Neo4j using a Cypher query
This scenario applies only to Talend products with Big Data.
This scenario describes a Job that first imports employees data from a CSV file into a
Neo4j database using a Cypher query, and then displays the information on the
console.
Adding and linking components
-
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, -
a tFileInputDelimited component,
to read the source data from a CSV file, -
a tNeo4jRow component, to write
the employees data to the Neo4j database with a Cypher query, -
a tNeo4jIntput component, to read
the employees data from the Neo4j database, -
a tLogRow component, to display
the data on the Run console,
and -
a tNeo4jClose component, to close
the Neo4j database connection opened by the tNeo4jConnection component.
-
-
Link the tNeo4jConnection component to
the tFileInputDelimited component using a
Trigger > On
Subjob Ok connection. -
Link the tFileInputDelimited component to
the tNeo4jRow component using a Row > Main
connection. -
Link the tFileInputDelimited component to
the tNeo4jIntput component using a
Trigger > On
Subjob Ok connection. -
Link the tNeo4jIntput component to the
tLogRow component using a Row > Main
connection. -
Link the tNeo4jIntput component to the
tNeo4jClose component using a Trigger > On Subjob
Ok connection. -
Label the components to better identify their roles in the Job.
Configuring the components
Configuring a Neo4j database connection
-
Double-click the tNeo4jConnection
component to open its Basic settings view
on the Component tab. -
From the DB Version list, select Neo4J
2.X.X. -
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.In this example, you will use Neo4j in REST mode; to connect to a remote
Neo4j server in embedded mode, clear the Use a remote
server check box and specify the Neo4j data file directory in
the Database path field.
Configuring data import
-
Double-click the tFileInputDelimited
component to open its Basic settings view
on the Component tab. -
In the File name/Stream field, specify
the path to the CSV file that contains the employees data to read.The input CSV file used in this example is as follows:1234567891011employeeID;employeeName;age;hireDate;salary;managerID1;Rutherford Roosevelt;38;06-10-2008;13336.58;m52;Warren Adams;43;05-22-2008;11626.68;m63;Andrew Roosevelt;55;04-01-2007;10052.95;m44;Herbert Quincy;54;06-14-2007;10694.71;m65;Woodrow Polk;33;08-14-2007;13751.50;m46;Theodore Johnson;47;01-26-2008;12426.87;m67;Benjamin Adams;32;02-25-2008;10438.65;m48;Woodrow Harrison;51;10-11-2008;11188.27;m59;George Truman;40;04-28-2008;14254.49;m510;Harry Jackson;38;04-01-2008;12798.78;m6 -
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. -
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 six columns: employeeID
(integer), employeeName (String),
age (Integer), hireDate (Date), salary (Double), and managerID (String).When done, click OK to close the
Schema dialog box and propagate the
schema to the next component. -
Double-click the tNeo4jRow component to
open its Basic settings view on the
Component tab. -
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. -
In the Query field, type in the Cypher
query to be executed by the component.In this example, type in the following query to create nodes with the
label Employees and six properties, to
hold the data from the input flow:-
ID, which will take the value
of the variable parameter id, -
Name, which will take the value
of the variable parameter name, -
Age, which will take the value
of the variable parameter age, -
HireDate, which will the value
of the variable parameter hire_date, -
Salary, which will take the
value of the variable parameter salary, and -
ManagerID, which will the value
of the variable parameter manager_id.
1"CREATE (n:Employees{ID:{id}, Name:{name}, Age:{age}, HireDate:{hire_date}, Salary:{salary}, ManagerID:{manager_id}})" -
-
In the Parameters table, type in the
variable parameters in the Parameter field
in accordance with your Cypher query , and map each of them with an input
schema column by selecting it from the Parameter
value list field.
Configuring data retrieving and display
-
Double-click the tNeo4jInput component to
open its Basic settings view. -
Select the Use an existing connection
check box to reuse the connection opened the tNeo4jConnection component. -
Click the […] button next to Edit schema and define the schema corresponding
to the node properties you want to retrieve and display.When done, click OK to close the
Schema dialog box and propagate the
schema to the next component.The defined schema columns automatically appear in the Mapping table. -
In the Query field, type in the Cypher
query to match the data to read from the Neo4j database. In this example,
use the following Cypher query to retrieve all the properties of all the
nodes with the label Employees.1"MATCH (n:Employees) RETURN *;" -
Fill the Return parameter field for each
schema column with a return parameter in double quotes to map the node
properties in the Neo4j database with the schema columns. -
Double-click the tLogRow component to
open its Basic settings view, and select
the Table (print values in cells of a
table) option to display the retrieved information in a
table.
Executing the Job
- Press Ctrl+S to save the Job.
-
Press F6 or click Run on the Run tab to run
the Job.The employees data in the CSV file is written to the Neo4j database and
displayed on the console.
Importing data from a CSV file to Neo4j and creating relationships using
a single Cypher query
This scenario applies only to Talend products with Big Data.
This scenario describes a Job that imports family information from a CSV file into a
remote Neo4j database and create relationships between persons and families using a
single Cypher query through a tNeo4jRow component.
example:
1 2 3 4 5 6 7 |
Name;Gender;Age;Family Jenny;Female;24;the Johnsons Jack;Male;26;the Johnsons Richard;Male;35;the Blacks Anne;Female;36;the Whites Helen;Female;28;the Blacks Tom;Male;38;the Whites |
As MERGE
is used with LOAD CSV
in this example, to ensure
the Cypher query is executed in an efficient way, another tNeo4jRow component is used to create an index on the property to
merge.
Adding and linking components
-
Create a Job and add two tNeo4jRow
components to the Job by typing the component name in the design workspace
or dropping them from the Palette. -
Link the components using a Trigger >
On Sub Job Ok connection. -
Label the components to better identify their roles in the Job.
Configuring the components
Creating an index
-
Double-click the first tNeo4jRow
component to open its Basic settings view
on the Component tab. -
From the DB Version list, select
Neo4J 2.X.X. -
Select the 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. -
In the Query field, type in the following
query to create an index on the property you are going to merge, which is
the name property of the Family nodes in this example:1"CREATE INDEX ON :Family(name)"
Importing data and creating relationships
-
Double-click the second tNeo4jRow
component to open its Basic settings view
on the Component tab. -
From the DB Version list, select
Neo4J 2.X.X. -
Select the 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. -
In the Query field, type in the following
Cypher query to import family data from the CSV file, create relevant
Person and Family nodes, and create relationships between persons and
families:1234"LOAD CSV WITH HEADERS FROM 'file:E:/Talend/Data/Input/families.csv' AS csvLine FIELDTERMINATOR ';'MERGE (family:Family { name: csvLine.Family })CREATE (person:Person { name: csvLine.Name, gender: csvLine.Gender, age: toInt(csvLine.Age)})CREATE (person)-[:From]->(family)"
Executing the Job and checking the result
-
Press Ctrl+S to save the Job, and press
F6 or click Run on the Run tab to run
the Job. -
In the address bar of your Web browser, enter the URL of the Neo4j
database browser,http://localhost:7474/
in this example, and
enter the following Cypher query in the command line to view the Person and Family nodes linked via the relationship From:1MATCH (a:Person)-[:`From`]->(b:Family) RETURN a,b;As shown in the graphic view, nodes labeled Family and Person have
been created and the nodes of persons from the same families are linked with
the relevant Family nodes via the
relationship From.