As well as taking data from several types of files, PDI is capable of sending data to different types of output files. All you have to do is redirect the flow of data towards the proper output step.
As a starting point, we will demonstrate how to generate a plain text file. In this case, we will generate a file with dates:
- From the code in Chapter 2, Getting Started with Transformations open the Transformation that generates dates, date_range.ktr. Save it under a different name.
- Double-click the second Calculator step. We will use this step for adding more fields related to each date. Fill the grid as follows:
Adding fields in a Calculator step
- Expand the Output branch of the Steps tree, look for the Text file output step and drag it to the work area.
- Create a hop from the Calculator step to this new step.
- Double-click on the Text file output step icon and give it a name. As Filename, type the full name for the file to generate, for example, D:/LearningPDI/files/dates.
- In the Content tab, leave the default values.
- Select the Fields tab and configure it as shown next:
Configuring the fields grid in an output step
- Click on OK.
- Save the Transformation and run it.
- Browse for the new file and open it. It will look as follows:
a_single_date;year;month;day;week_of_year;quarter
2017-01-01;2017;1;1;52;1
2017-01-02;2017;1;2;1;1
2017-01-03;2017;1;3;1;1
2017-01-04;2017;1;4;1;1
2017-01-05;2017;1;5;1;1
2017-01-06;2017;1;6;1;1
2017-01-07;2017;1;7;1;1
2017-01-08;2017;1;8;1;1
2017-01-09;2017;1;9;2;1
2017-01-10;2017;1;10;2;1
...
Note that if you run this Transformation more than once, PDI will overwrite the destination
file. This is the default behavior. If you specify an existing file, the file will
be replaced by a new one, unless you check the Append checkbox, present in some of the output steps. PDI will generate the output file
even if there is no data to send to it. If you don't want empty files, there is a
way for preventing the situation. Just check the Do not create file at start flag present in most output steps. If you do this, the file will not be created until
the first row of data comes to it.