The Talend Replace data or tReplace field used to replace a whole word or part of a word in the input rows and returns the output. We can use this Talend Replace data field to change the wrongly type data etc.
In this Talend Replace data example, we used the SQL Server database Customer table. The following screenshot shows the data inside that table.
Talend Replace or tReplace Example
First, drag and drop the DBConnection, DBCommit, and DBInput to establish a SQL Server Connection. Next, we selected the Customers table from the metadata.
Next, drag the Talend tRepalce from palette to job design. As you can see from the below tooltip, tReplace replaces and expression with another one.
Please connect the DBInput main row to tReplace. Mostly, the input columns will sync with the tReplace. If that is not the case, click on the Sync columns button.
Within the Components tab, there is a simple mode and an advanced mode. You can use advanced mode to write a regular expression. In the Search/Replace section, we have
- InputColumn: Please select the column you want to use for search and replace.
- Search: Please provide the search term that you want to search inside the column.
- Replace with: Write the replacement term in this section.
- Whole word: If you wish to perform on the entire word or part of a word.
- Case Sensitive: Do you want to achieve the search in a case sensitive.
Before we perform anything, click the Edit Schema button to check or alter the tReplace schema as per your requirements.
Next, click on the Add (plus) button. By default, it adds the first column, i.e., EmpID and defaults text.
Please use the drop-down box to select the required column. Here, we chose the column as Education, Search term as Education, and Replace with BTech.
After finishing the tRepalce Component configuration, we are using the DBOutput to save the Talend tReplace output in a SQL Database. Here, we are creating the Talend_repalce table as the destination table.
Let us run the Talend Replace data Job.
Let me open the Management studio to check the Talend tReplace result.
This time, we are using two more fields and run the job. It means Talend tRepalce has to replace the Pro part (not the complete word) in the Occupation field with ABCD and John in the FirstName column with Suresh.
Please check the Talend tReplace result.
Let me select the Talend Replace field Advanced mode. As you can see, here, we can use the regexp pattern to search the string.