In some cases you are fortunate that decent test data is available, but unfortunately this is not always the case. Therefore I’m going to show you how you can easily create your own test data. This test data should be good enough for a development phase.
Talend Studio offers you a component and some functions to create your own test data. In this “how to” we are going to create customer data with the tRowGererator component.
1. Create a new job
- Name your job “how_to_create_random_test_data”
2. Add the tRowGenerator component
- Drag and drop the tRowGenerator component to your canvas
- Select the component and open the component tab
- Edit the schema:
3. Edit tRowGenerator
- Select you tRowGenerator component again
- Open to the component tab and click at “RowGenerator Editor”
The tRowGenerator component offers u the use of some standard functions, but you can also set your own expression. We are going to set our own expression for the CustomerId because we want to use a sequence. Follow the steps below:
- Select the row with the CustomerId and add your own expression by pressing the value column
- Add the following code: Numeric.sequence(“s1”,1,1)
- You can preview your expression by clicking the preview button
3.2 FirstName and lastname
Talend offers you a TalendDataGenerator function to create a string that looks like a firstname or lastname.
- Select the row in the upper part (under schema)
- Select the functions TalendDataGenerator.getFirstName() and TalendDataGenerator.getLastName()
- Press the preview button again to see the results
- Add your own expression by selecting the value column.
- Add the following code:
(Numeric.random(0,100)).toString() +” “+ TalendDataGenerator.getUsStreet()
In this case we are using a random numeric value and convert this value to a string value because we want to concatenate it with the getUsStreet function, which is a also a string value.
If you are interested in other Talend methods to convert between different datatypes then read the following articles:
3.4 Address 2
- Add your own expression by pressing the value column
- Add the following code:
TalendDataGenerator.getUsCity()+ “, ” +
TalendDataGenerator.getUsStateId() + ” ” +
(Numeric.random(0,99999)).toString()+ “-” +
3.5 Add the tLogRow component
- Add the tLogRow component to your canvas and connect it to your tLogRow (Row – Main)
4. See the results of your test data job
- Run your job
- The default Number of Rows for RowGenerator is 100, but I have changed it to 20. You can set this value in the tRowGenerator component.