In this scenario context variables are added to override the connection credentials and
thus to switch between a pre-Production database and a Production database at execution
time.
Before you begin
-
You have previously created a connection to the system storing your source
data, here a MySQL connection.
-
You have previously added the dataset holding your source
data.
Here, a table containing contact data including customer identifiers, names,
addresses, countries, credit limits, etc.
- You also have created the destination connection, here a Test dataset where
you will store output logs.
Procedure
-
Click ADD
PIPELINE on the Pipelines page. Your new pipeline opens.
-
Give the pipeline a meaningful name.
Example
Switch from a MySQL Pre-Prod to PROD table
with context variables
-
Click ADD SOURCE to
open the panel allowing you to select your source data, here MySQL contact table. A sample of your data is
displayed in the preview panel.
-
Click
and
add a Type converter processor to the
pipeline. The Configuration panel opens.
-
Give a meaningful name to the processor; convert credit type for example.
-
In the Converters area:
-
Select .creditlimit in the Field
path area, as you want to convert the records
corresponding to the user financial credit limits.
-
Select Double in
the Output type list as you want
to convert the credit limit values from a String to a Double type, which
will then allow you to perform calculations on these values.
-
Click SAVE to save your configuration.
You can see that the records about credit limits are converted to a Double
type.
-
Click
and
add an Aggregate processor to the
pipeline. The Configuration panel opens.
-
Give a meaningful name to the processor; calculate average credit limit for
example.
-
In the Operation area:
-
Select .creditlimit in the Field
path area, as you want to perform a calculation
operation on the records corresponding to the user financial credit
limits.
-
Select Average
in the Operation list as you
want to calculate the average credit limit for this list of
customers.
-
Click SAVE to save your configuration.
You can see that the records about credit limits are
converted to a Double type.
-
Click the ADD
DESTINATION item on the pipeline to open the panel allowing to
select the Test dataset that will hold your output logs.
-
(Optional) If you execute your pipeline at this stage, you
will see in the logs that:
- the pipeline was successfully executed and 52 records have been
read.
- no context variables were set in this pipeline.
-
Go back to the Connection tab of the MySQL contact
table source to add and assign a variable:
-
Click the
icon next to the JDBC URL parameter to open the
[Add a variable]
window.
-
Give a name to your variable, PROD connection string data for
example.
-
Enter the variable value that will overwrite the
default resource to be retrieved, jdbc:mysql://myprodconnectionstring.us-east-1.rds.amazonaws.com:3306/mytable
for example.
-
Enter a description if needed and click ADD.
-
Now that your variable is created, you are redirected
to the [Assign a variable]
window that lists all context variables. Select yours and click
ASSIGN.
Your variable and its value are assigned to the
JDBC URL parameter of the
MySQL dataset, which means the JDBC URL that points to the production
MySQL table will overwrite the JDBC URL you have defined previously.
Instead of retrieving data from the pre-Production table, the Production
table data will be retrieved.
-
Click SAVE to save your configuration.
Once the variable is assigned, the
icon will be displayed to indicate that a variable has been set in
the pipeline.
-
On the top toolbar
of Talend Cloud Pipeline Designer,
select your run profile in the list (for more information, see Run profiles).
-
Click the
run icon to run your
pipeline.
Results
Your pipeline is being executed, the data is aggregated and corresponds to the
context variable you have assigned to the source and destination connection strings:
- In the pipeline execution logs, you can see that a higher
number of records have been read (1153).
- You can also see the context variable value used to
retrieve the data from the Production table at execution time.