Performing multiple operations on customer records using Python - Cloud

Talend Cloud Pipeline Designer Processors Guide

author
Talend Documentation Team
EnrichVersion
Cloud
EnrichProdName
Talend Cloud
task
Design and Development > Designing Pipelines
EnrichPlatform
Talend Pipeline Designer

Before you begin

  • You have previously created a connection to the system storing your source data.

    Here, a database connection.

  • You have previously added the dataset holding your source data.

    Here, a table of customers with first name, last name, registration date and revenue fields (download the filter-python-customers.json file from the Downloads tab in the left panel of this page).

  • You also have created the connection and the related dataset that will hold the processed data.

    Here, a file stored on HDFS.

Procedure

  1. Click ADD PIPELINE on the PIPELINES page. Your new pipeline opens.
  2. Give the pipeline a meaningful name.
    Process Customers with Python
  3. Click ADD SOURCE to open the panel allowing you to select your source data, here a table of customers.
  4. Select your dataset and click SELECT DATASET in order to add it to the pipeline.
    Rename it if needed.
  5. Click and add a Python processor to the pipeline. The Configuration panel opens.
  6. Give a meaningful name to the processor.
    aggregate name - convert to euros - calculate registration date
  7. In the Map list, select Map.
  8. In the Python code area, type in:
    date=input['RegistrationDate'].split("/")
    year=date[2]
    
    output['id'] = input['id']
    output['fullname'] = input['Firstname'] + " " + input["Lastname"]
    output['euro_revenue'] = int(input['Revenue']) * 0.83
    output['number_year_registrated'] = 2019 - int(year)
    This code allows you to:
    • concatenate the first name and last name fields

    • convert the revenue to euros

    • calculate the number of year the customer has been registered

  9. Click SAVE to save your configuration.
  10. Click the ADD DESTINATION item on the pipeline to open the panel allowing to select the dataset that will hold your processed data.
    Rename it if needed.
  11. (Optional) Look at the preview of the Python processor to compare your data before and after the operations.
  12. On the top toolbar of Talend Cloud Pipeline Designer, select your Run Profile in the list (for more information, see Execution profiles).
  13. Click the run icon to run your pipeline.

Results

Your pipeline is being executed, the data is processed according to the conditions you have stated in the Python code and the output is sent to the target system you have indicated.