Example: let's assume that we have Project B that loads data from a file and the file name is defined by a parameter Param1. In order to run Project B for several files, we create Project A with a list of files and iterate (loop) through this list, passing every file name from Project A to Project B as parameter Param1. The picture below illustrates such scenario:
As you can see from this example, Project B is run as many times as the number of values in Table 1 of Project A, i.e. 3 values = 3 iterations.
Transformation "Iterate"In EasyMorph iterations are arranged using Iterate transformation.
This transformation has two modes:
- Iterate – run another project N times, return nothing (the other project is supposed to have at least one export transformation)
- Iterate and Append – run another project N times, return N final states of the specified table in that project, and append all of them into one table which becomes a result of the transformation
Design patternsIterations is a very versatile mechanism, useful in various cases:
- Processing a list of files
- Looping through a range of dates
- FOR .. NEXT style loops
- Nested iterations (A runs B that runs C)
- Reusable logic (A runs C, B runs C)
For those who used to traditional FOR .. NEXT loops iterations might look unusual at first. General design pattern with iterations is to build a list first, and only then iterate through it. For instance: take a list of dates, filter out weekends, then iterate.
Iteration lists can be loaded from an external file or a database. Also, there are several transformations in EasyMorph that generate lists:
- Calendar – generates a list of dates for specified time period, including optional columns such as day of week, weekend flag, etc.
- File List – generates a list of files in a specified folder, including optional columns such as file size or date created
- Folder List – generates a list of folders in a specified folder
- Sequence – generates a table with one column with numbers from 1 to N