Creating pseudo Components and Custom Routines in Talend

  • (4.0)

Creating PSEUDO COMPONENTS using tJavaFlex

Function tJavaFlex enables you to enter a personalized code in order to integrate it in TALEND program. With tJavaFlex, you can enter the three java-code parts (start, main and end) that constitute a kind of component dedicated to do a desired operation.

MindMajix Talend Training course is designed to make you an expert in developing ETL solutions using Talend platform. Start Learning! 

Purpose tJavaFlex lets you add Java code to the Start/Main/End code sections of this component itself.

Configuring the tJavaFlex component

  • Double-click tJavaFlex to display its Basic settings view and define the component’s properties.

  • Click Sync columns to retrieve the schema from the preceding component.
  • In the Start code field, enter the code to be executed in the initialization phase.In this example, the code indicates the initialization of the tJavaFlex component by displaying the START message and defining the variable to be used afterwards in the Java code:
System.out.println("## STARTn#");
int i = 0;
  • In the Main code field, enter the code to be applied on each line of data.In this example, we want to show the number of each line starting from 0 and then the number and the random text transformed to upper case and finally the random date set in the editor of tRowGenerator. Then, we create a condition to show if the status is true or false and we increment the number of the line:
System.out.print(" row" + i + ":");
System.out.print("# number:" + row1.number);
System.out.print (" | txt:" + row1.txt.toUpperCase());
System.out.print(" | date:" +;
if(row1.flag) System.out.println(" | flag: true");
else  System.out.println(" | flag: false");


In the End code field, enter the code that will be executed in the closing phase.

In this example, the code indicates the end of the execution of tJavaFlex by displaying the END message:

System.out.println("#n## END");

Frequently Asked TALEND Interview Questions & Answers

Creating Custom routines in Talend or Jasper ETL

Lot of time, we come across a situation where we want to use the custom routines/functions while creating Talend Job. Custom routines can be handy and re-usable code when required to be used more than one time.
Here, let us create a simple routine to convert String to Date data type. The user will pass the date in string format and the actual date format of the string to the routine and in return routine will provide the Date.

Follow below mentioned steps to create a user routine:

1. Right Click on Routines in Repository Pane and Select Create routine.

2. Provide the Name to the Routine in the New Routine window and click Finish.

3. Create a required function in the Routine. Copy the below code to create a function convert2Date.

package routines;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class string_to_date {
public static Date convert2Date(String string_date,String date_format) throws Exception
     SimpleDateFormat sdf = new SimpleDateFormat(date_format);
     Date transformed_date = sdf.parse(string_date);
     return transformed_date;

Now our routine is ready. Its time to use this routine.

4. Create a new Job and drag tJava component to the Job designer.

5. Here we will call the routine. We will pass the sample date “2013-03-15” in String format and its format “yyyy-MM-dd” as well, to use the routine write routines. and press ctr+tab to access all the available routines and select string_to_date.convert2Date.

Copy and paste below code

String string_date = "2013-03-15"; 
String date_format = "yyyy-MM-dd";
Date transformed_date = routines.string_to_date.convert2Date(string_date, date_format);
Calendar cal = Calendar.getInstance();
System.out.println("nYear part is  = " + cal.get(Calendar.YEAR));
System.out.println("nMonth part is = " + cal.get(Calendar.MONTH));
System.out.println("nDay part is   = " + cal.get(Calendar.DAY_OF_MONTH));
System.out.println("String has been transformed to Date datatype = "+ transformed_date.toString() );

Now our job is complete. It’s time to execute it.

Now, you can see that date in the form of String has been converted to Date data type. You can call this routine whenever you require to convert string to Date. Just provide the string literal and its format to the routine defined above.

Explore TALEND Sample Resumes! Download & Edit, Get Noticed by Top Employers!Download Now!

Popular Courses in 2018

Get Updates on Tech posts, Interview & Certification questions and training schedules