Pseudo Components and Custom Routines in Talend

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.

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

If you would like to Enrich your career with a Talend certified professional, then visit Mindmajix - A Global online training platform: “Talend Certification Training”  Course. This course will help you to achieve excellence in this domain.

Configuring the tJavaFlex component

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

Configuring the tJavaFlex component

  • 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:

MindMajix Youtube Channel

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:
 

Main code

  • 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");

End code

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:

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

Create routine

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

New Routine

------        Check Out Talend Tutorials        ------

  • 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.

  • Create a new Job and drag tJava component to the Job designer.
  • 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.
Explore TALEND Sample Resumes! Download & Edit, Get Noticed by Top Employers!Download Now!

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();
cal.setTime(transformed_date);
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.

Execution

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.

Course Schedule
NameDates
Talend TrainingOct 19 to Nov 03View Details
Talend TrainingOct 22 to Nov 06View Details
Talend TrainingOct 26 to Nov 10View Details
Talend TrainingOct 29 to Nov 13View Details
Last updated: 03 Apr 2023
About Author

Ravindra Savaram is a Technical Lead at Mindmajix.com. His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter.

read less
  1. Share: