# Using Dynamic Layout Template Mapping in Astera

The *Dynamic Layout/Template Mapping* feature in Astera enables users to create a template dataflow that can be used to process multiple files and generate copies of the same dataflow, without having to change the mapping links individually for each source dataset. Upon execution, Astera will replace the values dynamically and generate a new dataflow automatically for all source files.

## **Benefits of Template Mapping**

* Running your routine processes does not require you to design and map your ETL flows every time.
* ETL pipelines can be run without any dependence on the development environment.
* Template mapping also facilitates scheduling repetitive, routine jobs for automation.
* Using runtime parameters, you can customize your templates to suit your changing requirements.
* Template mapping makes it all the more convenient for non-technical users to customize and deploy these templates in different business scenarios.

In this document, we will learn how to use the *Dynamic Layouts/Template Mapping* functionality in Astera.

## **Use Case: Auto-Generating Dataflows through Template Guide Maps**

Dataflow templates are reusable flows that can be customized using runtime parameters and generate copies of the same flow for multiple source files upon execution.

Let’s understand this with an example.

Here we have around 15 tables in a database, and we need to process the data in each of these tables through a dataflow. Following a traditional ETL mapping approach, we would need to design 40 different dataflows and run them separately. Although the records and layouts are different in each table, the data in each table is processed through a similar process that involves the following steps:

1. Data is extracted using the [*Database Table Source*](https://documentation.astera.com/astera-data-stack-v9/dataflows/sources/database-table-source) object in Astera
2. Data is written into a .csv file using the [*Delimited File Destination*](https://documentation.astera.com/astera-data-stack-v9/dataflows/destinations/delimited-file-destination) object

Mapping the same flow to different source tables and destination paths, manually, can be time-consuming, inefficient, and prone to human errors. However, by designing and creating a dataflow template, you can map the task to the template which will generate a copy of the same dataflow for each table, with unique source and destination paths.

Let’s see how this works in Astera.

## **Creating a Template Dataflow in Astera**

To create a template dataflow, drag and drop the relevant source object from the Sources section in the Toolbox. The *Dynamic Layout* option for template mapping is supported in the *Database Table Source*, *Excel File Source*, and *Delimited File Source* in Astera. In this example, our source data is stored in a database table, so we will use a *Database Table Source* object to retrieve our data.

Drag and drop this object from the *Sources* section in the *Toolbox* onto the dataflow designer.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FgXzn0WNTDymt2bTiV4PQ%2F0.png?alt=media)

Now, right-click on the *Database Source* object’s header, and select *Properties*.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FA9SAVS4Tth4W0NBcyF3T%2F1.png?alt=media)

This will open a new window where you will need to provide details to configure a connection with the database.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2F1Mc1TtjUfNhRa4kDs8Z8%2F2.png?alt=media)

Once the connection is established, click *Next* to proceed to the next screen.

Here, you need to pick a table from the database. In this case, We will select the *Customers* table from the list.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2Fw3ARMm10fyRE5IEWftjl%2F3.png?alt=media)

Leave the other options as default, and scroll down to the *Dynamic Layout* section on the same screen.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FOaAKwX52UJSF9pGlgbAF%2F4.png?alt=media)

Check the *Dynamic Layout* option. This will enable the other two options in this section.

* *Delete Fields in Subsequent Objects:* When this option is checked, it will remove all elements already present in the subsequent objects.
* *Add Fields in Subsequent Objects:* When this option is checked, it will populate the fields from the source table in the subsequent objects.

Both these options are checked by default and enabled when you check the *Dynamic Layout* option.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FbtZfcsNrge2Z70Oefezt%2F5.png?alt=media)

Once done, click *OK* to exit the screen.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FUCEiNGn63vQ3jyiGa5is%2F6.png?alt=media)

Now, if you look at the *Database Table Source* object, you can see this small icon or flag, DYN, over the header. This denotes that the source object has been set to work with dynamic layouts.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FxsdSRGrpl6QhSacTQJXN%2F7.png?alt=media)

Now, drag and drop a *Variables* object from the *Resources* section in the *Toolbox* onto the designer.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FIXWWPECvZZIhZmgtc8Q5%2F8.png?alt=media)

Using this *Variables* object, we will define input parameters for the source table. Right-click on the *Variables* object’s header, and select *Properties*.

This will open a new window where we will specify the input parameters or variables for the source table.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FDRbBHyv2wLDBjQLcCrHA%2F9.png?alt=media)

* *Name:* TBLName
  * This is the name of the input variable and will be hardcoded in the *Config Parameters* window of the *Database Table Source* object.
* *Data Type:* String
* *Variable Type:* Input
* *Default Value:* Employees
  * The *Default Value* can be the name of any table in your source database that you want to process in the template dataflow. Here, we have provided the *Default Value* as ‘Employees’ since we want to process the *Employees* table through the template dataflow we are designing.

Once you have specified the parameter details, click *OK*.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FC1Wo8D6S7utT5N7W9M4z%2F10.png?alt=media)

Now right-click on the *Database Table Source* object’s header, and select *Properties*. Select the *Config Parameters* screen.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FPqDsRyizOPgV5FXRobNG%2F11.png?alt=media)

Here, you need to provide details of the parameters you have specified in the *Variables* object.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2F6TuMMCtOPL8QhrGoBXY8%2F12.png?alt=media)

Click the *Value* field for *TableInfo.Name*, and write {Variables.TBLName}. Once done, click *OK.*

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FPEGP8LaPgEvUmsqUyiaZ%2F13.png?alt=media)

Now, as per our use case, we want to write the source data to a *Delimited File Destination*. For this, let’s drag the *Delimited File Destination* object from the Destinations section in the Toolbox onto the designer.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2F27ip7rIyU0cPuV86KYRl%2F14.png?alt=media)

Now map fields from the *Database Table Source* object to the *Delimited File Destination* object.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FfNP9w5zV3ck5B9EdDMM9%2F15.png?alt=media)

Right-click on the *Delimited File Destination* object’s header, and select *Properties*.

This will open a new window where you need to point the path to the location where you want to save your output file. Provide a name and location, and click *Save*.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FJXsYvqR3ElQ75r3Bvuka%2F16.png?alt=media)

Since we will be using this dataflow template for multiple tables in our database, the destination file path should be dynamic so that it can generate a new output file with a unique name for each table it processes. To do this, go to the *Config Parameters* screen in the *Delimited File Destination* object.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2Fk82J7pgsLyy7l9i4uBMd%2F17.png?alt=media)

Here, you need to provide parameters that will generate a new output file every time a table is processed through the dataflow.

Let’s write the following value for the *Destination File*: \arrakis\share\Fiza Baig\TemplateMap\_Output{Variables.TBLName}.csv

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2Fj2vVXVyesCdokp0enysx%2F18.png?alt=media)

Once done, click *OK* to close the window.

Now right-click on any mapping link connecting a field from the source to the destination, and select *Template Map Properties* from the list.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FcEWwgzPrYafvA7Qw1e5q%2F19.png?alt=media)

This will open a new window where you will need to specify the template map type.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FwDHeICZ5rzZeDSjE3d7U%2F20.png?alt=media)

Click on the *Template Map Type* drop-down list. You can see two options:

* *Guide Map:* This mapping link serves as a pointer between two objects in a dataflow and determines how data flows between them. The *Guide Map* works independently of the different fields in a source object. As in, it merely defines the path of data from the source to the destination and has nothing to do with whichever field it is mapped to.
* *Conditional Map:* *Conditional Map* specifies a set of conditions for a particular field in Source and Destination file layouts.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2F42wcCQOsSgOloJCMVQnN%2Fimage.png?alt=media&#x26;token=1ef179ba-565b-4c88-820d-8702b0a4f27f" alt=""><figcaption></figcaption></figure>

Let’s select *Guide Map* as our *Template Map Type and* click *OK.*

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2Fqdn0lGA643sdOp7XWN2W%2Fimage.png?alt=media&#x26;token=8a0a977f-68ec-4a32-aee7-8d107ffe116f" alt=""><figcaption></figcaption></figure>

You can now see the *Guide Map* written above the mapping link.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FydTApOmI7aQiWRETawCf%2Fimage.png?alt=media&#x26;token=d5065f0a-fd96-45d1-a2dd-b802c5948047" alt=""><figcaption></figcaption></figure>

Our template dataflow is ready. Now let’s run the dataflow. You can observe the progress in the *Job Progress* window.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2F0r2UGmKJpmLxmMHXyiNK%2Fimage.png?alt=media&#x26;token=f1c2f183-94e9-461f-9af3-5876221ae1de" alt=""><figcaption></figcaption></figure>

If you look at the job trace, you can see that Astera has generated a new dataflow (*DynLayoutProcessed.df*) based on our template dataflow. The output file too, which is a CSV file in this case, has been generated at the specified location. You can find clickable links to the new dataflow as well as the output file in the job trace.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FLOtB9QQzywJMrkPQBQnA%2Fimage.png?alt=media&#x26;token=40bf2eae-208a-4f03-8d40-ad2821ca38bf" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**Note:** To be able to access and open the new dataflow in Astera, you need to be logged on to the Astera Integration Server. For this, go to *Services > Astera Integration Server > right-click > Properties > Log on*.
{% endhint %}

Let’s open this new dataflow by clicking on the link in the job trace.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FauEHGk6yJAHoY7aGp0iP%2Fimage.png?alt=media&#x26;token=3adccc89-7c27-4b5a-a20b-59bb4ea92121" alt=""><figcaption></figcaption></figure>

You can see that this new dataflow that has been generated automatically is the exact copy of the template dataflow we created in the previous steps.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FCjVsyDvG1rvRfOcqqsn8%2Fimage.png?alt=media&#x26;token=d6a46259-3e2c-4e4f-bc4b-5707e4f6214b" alt=""><figcaption></figcaption></figure>

Based on the *Default Value*, *Employees* in the *Variables* object, the *Database Table Source* object has automatically picked the table from the database, replacing the *Customers* table in the template dataflow, and has populated the fields from the *Employees* table in the Source as well as Destination objects.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2Fg8SFe0V3yAhl1xvnkjbz%2Fimage.png?alt=media&#x26;token=d651e559-8ccb-4bab-9541-08a2a2593620" alt=""><figcaption></figcaption></figure>

Click on the output file link in the job trace to open the CSV file in Astera.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FM4qWenviwBON55WpooHa%2Fimage.png?alt=media&#x26;token=3027dd39-7dbd-4838-a5bc-1a5520602cc1" alt=""><figcaption></figcaption></figure>

You can see that records from the *Employees* table have been written into the output file.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2F1Ni7qezqOU5lTleHnCya%2Fimage.png?alt=media&#x26;token=dcdf5de8-eb46-4714-978c-72693d444fc7" alt=""><figcaption></figcaption></figure>

## **Automating Template Maps for the Entire Database**

Our source database contains multiple tables and we want to run all of them through the same process we defined in our template dataflow. We can orchestrate this entire process for automation using the workflow and scheduler component in Astera.

Let’s see how this is done.

Open a new workflow by going to *File menu > New > Workflow*.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2F2ldBbwGPZmfXui5btGyI%2Fimage.png?alt=media&#x26;token=6f6d06d8-9fc7-44d2-824a-e552f654e516" alt=""><figcaption></figcaption></figure>

This will open a new workflow window in Astera.

Drag-and-drop the *ADO.Net Metadata Collection* object from the Sources section in the Toolbox onto the designer. The *ADO.Net Metadata Collection* object provides metadata to the database we want to read the data from. However, if you are working with file sources such as Excel or Delimited, you can use the *File System Items Source* to provide metadata for your source files.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FnEoSssleiJwBjYqayAB1%2Fimage.png?alt=media&#x26;token=b3933077-d2f0-4cec-8adc-f4503d71cf13" alt=""><figcaption></figcaption></figure>

Right-click on the *ADO.Net Metadata Collection* object’s header, and select *Properties.*

This will open a new window where you will need to provide details to establish a connection with the database. Once the connection is established, click *Next*.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FBWGYcWFNSsgmMOyvkFze%2Fimage.png?alt=media&#x26;token=6c1ed845-7d52-491c-81d5-a95202068afb" alt=""><figcaption></figcaption></figure>

Here, you need to select the *ADO Collection* from the list. Click on the drop-down and select *Tables* from the list.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FS89ju8fG9Iua5DfP2WNE%2Fimage.png?alt=media&#x26;token=ff6da75c-50fa-4940-b1dd-a9d4622b8f3e" alt=""><figcaption></figcaption></figure>

This will provide us with metadata about the *Tables* in the database. Now, click *OK* to exit the window.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2F4kj2Gd6t7dtKZMYpKA66%2Fimage.png?alt=media&#x26;token=066a1a8c-2571-43b4-aaac-87f7f1792ea7" alt=""><figcaption></figcaption></figure>

Right-click on the *ADO.Net Metadata* object’s header again, and set it to run on *Loop*. This is because we have multiple tables in our database, and we want to process them all through the dataflow.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2F4qiLYrLtcflpBwR3oEWA%2Fimage.png?alt=media&#x26;token=a8ba3c89-3f7c-4e3e-8064-efbba9085b24" alt=""><figcaption></figcaption></figure>

Now, drag a *Run Dataflow* task object from the *Workflow Tasks* section of the *Toolbox*, and drop it onto the designer.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FOJf1xihNf4xX1cYXjJoX%2Fimage.png?alt=media&#x26;token=21c56c23-6185-4c18-bf31-afeb34650a23" alt=""><figcaption></figcaption></figure>

Map the *Ado.Net* object from the header node to the *RunDataflow* task.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2Fgg2T7s3AFUDbtH2GDZ8j%2Fimage.png?alt=media&#x26;token=1e995349-8f47-4363-b02d-6ab7109af8bd" alt=""><figcaption></figcaption></figure>

Now, right-click on the *RunDataflow* task object’s header and select *Properties*.

This will open a new window where you will need to provide the *Path* to the template dataflow. Click *OK.*

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2F64ERRimINmCXzP8CELrN%2Fimage.png?alt=media&#x26;token=b64745ba-3cc9-4fb2-a01b-1ee2e7433aad" alt=""><figcaption></figcaption></figure>

Now expand the *Input* node inside the *RunDataflow* task object and map the *TABLE\_NAME* field from the *ADO.NET* object to the *TBLName* field in the *RunDataflow* task object.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FlzopkHrtgTZ0GVfe29tq%2Fimage.png?alt=media&#x26;token=efb7aea4-da02-42be-9cc9-6386b4f5a75c" alt=""><figcaption></figcaption></figure>

Our workflow is now ready for run. Save it to your desired location and click the *Start Job* icon located in the main toolbar.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2F148D0SFaeW87XppWTuO0%2Fimage.png?alt=media&#x26;token=56184454-2f83-49ad-af03-7ff2f9e56d66" alt=""><figcaption></figcaption></figure>

This will start the job. You can see the progress in the *Job Progress* window.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2F6vrATc37zaXeC7hKq6in%2Fimage.png?alt=media&#x26;token=7cdfefe2-bfd6-41c6-aa9c-b04549f8bf9c" alt=""><figcaption></figcaption></figure>

You can see that all the tables in the database have been processed sequentially through the template dataflow and a new dataflow has been generated automatically for each table. You can open these dataflows as well as output files by clicking on the links in the job trace.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FgU8wAmQEaBx3B7YGfw9W%2Fimage.png?alt=media&#x26;token=714235ea-5543-4293-8940-9ab05a3645f4" alt=""><figcaption></figcaption></figure>

The output files too have been generated at the specified location.

<figure><img src="https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FhUR3ol5xkoRXTxY2qd2P%2Fimage.png?alt=media&#x26;token=afe5ad7d-4ef5-4c81-bcbf-43e087a3bfa6" alt=""><figcaption></figcaption></figure>

As mentioned earlier, you need to be logged on to the Astera Data Stack to be able to access and open the auto-generated dataflows in Astera.

The workflow can now be deployed on Astera's built-in Scheduler to be executed automatically, at a time and frequency of your choice.

This concludes using the *Dynamic Layout/Template Mapping* Feature in Astera. Please note that this is a beta version of the feature. The functionality is still in the testing phase and could change as we get user feedback on this feature. Should you have any suggestions or feedback, or come across a bug, please report to our [Support site](https://astera.zendesk.com/hc/en-us) or email us at [support@astera.com](mailto:support%40astera.com).
