Skip to main content

Posts

How to Create a Sequence in Talend

 The sequence routine allows you to create automatically incremented IDs, using a tJava component or any components for example tMap, tFixedFlowInput etc.. The code for defining the sequence is:  Numeric.sequence("s1",1,1). whenever you use this sequence Next time, it's value will be incremented by 1. For Example: following code will print 1,2,3 in a seperate line: System.out.println(Numeric.sequence("s1",1,1));  System.out.println(Numeric.sequence("s1",1,1)); System.out.println(Numeric.sequence("s1",1,1)); if you want your sequence to be printed from specific number, then use that number at the between, the last interger is for the interval. The following code starts a sequence from 102. Numeric.sequence("s1",102,1).
Recent posts

Iterate on Rows One by One

 To get a record from any data source for example from a delimated File containing huge records, you can simply use component tFlowToIterate. This component extract one record at a time, after preforming the required action, next record is fetched and will do the same for rest of the records as: Define the Schema in tFileInputDelimated component, set the variable in tSetGlobalVar component, use this value for the further operations.

Remove all the Empty Lines from a String

 When you are working with any data sources, there might be cases where there are multiple empty lines for a particular record or column, In such case you can remove such lines by simply using the custom java codes. Example: String s = "Hello \n+ "\n  Hi"+ "\n"; s.replaceAll("\n|\r[ \t|\r]*\n", " ");  ,this will do the required job for you.

Convert the Given Date to Any Format

 Suppose you have a date in the format yyyy/MM/DD HH:MM:ss, and you want to convert like DD-MM-yyyy HH:MM:ss. How will you do in Talend. I am going to show you demo. 1. If you want to display the current System date to any format, you can use talend Function as:  TalendDate.getDate("yyyy-MM-dd HH:MM:ss").  This will simply display the current date time in this format. For Example: 2021-09-23 15:09:56 Screenshot: Output of the Above code is: You can use this code whereever you want for example in the tJavaRow, tSetGlobalVar, tFixedFlowInput, tMap components etc... On the similar manner if we have date already given then for converting that date to specific format, first of all you need to parse the date and then give pattern of specific format. For parsing the date there is a function : suppose date = "2018/09/20 12:34:45" for parsing this date,  TalendDate.parseDate("yyyy/MM/DD HH:mm:ss", date); After parsing, you have to format the date using the specifi...

Get Unique Records

To get only the unique records from any data sources for Example csv file, excel file, etc.. use tUniqRow component of talend.  Example: Suppose we have following records in a csv file as: for getting the unique records simply is tUniqRow Component as get the desired result. In this component, define key field first and get desired result as:

Get N records from a CSV file and Store it in an Array

  Objective of the task is to pick up N(for example 5,10,100, etc..) records from csv File and put in an array. This can also be generic, you can post those records to web API OR perform any operations as per your requirement. Steps:  Count total number of rows(records) in a file. [ use component  tFileRowCoun t ].  Define 3 variables. one for total count of records, second for header, third is to limit the records.  [use component  tSetGlobalVar ] in the screenshot, i have used Header as 1 as the csf file contains Header. Also, you can start from specific records based on this value. Also Limit is set 10. you can take this value from context and configure it as per your needs. Apply loops until the variable Header is less than or equals to total row count. [use tLoop, in the condition use Header <= totalRowCount]  Get the data from delimated file, add Header and Limit variables in the coppresponding place. [ use component tFileInputDelimated ] The ...