Tree Transform

The Tree Transform in Astera Centerprise enables users to transform data in a hierarchical structure. Users can create new fields in the parent node based on the data in the collection/child node. Tree Transform supports rule-based routing, filtering, merging and sorting of data while maintaining its hierarchy.

In this document, we will learn to use Tree Transform in Astera Centerprise.

Use Case

In this case, we are using the XML/JSON File Source to extract our source data. You can download this sample data from here.


The source file contains customers’ information in the parent node and their orders and shipping details in the collection/child node.

You can preview this data by right-clicking on source object’s header > Preview Output.


A Data Preview window will open, displaying a preview of the hierarchical source data.


Now, we want to create a new field in the parent node that contains the count of orders that arrived late for each customer, and route these records to a destination file while maintaining the hierarchical format of the dataset.

This new field in the parent node will depend on two fields: RequiredDate and ShippedDate, that are already present in the collection/child node.

In other words, we are trying to transform a hierarchical data without flattening its structure. For this purpose, we will use the Tree Transform transformation.

Using Tree Transform

1. To get a Tree Transform from the Toolbox, go to Toolbox > Transformations > Tree Transform and drag-and-drop the Tree Transform object onto the designer.

![Untitled Project1f2a39c.autosave](tree-transform.assets/Untitled Project1f2a39c.autosave.gif)

The transformation object is empty right now. This is because we haven’t mapped any fields to it yet.

2. Auto-map source fields onto the transformation by dragging and dropping the root node of the source object CustomerOrders onto the root node of the transformation object – TreeXform.


Now that the mapping is done, let’s configure the TreeXfrom object.

Configuring the Tree Transform Object

1. Right-click on the object’s header and select Properties from the context menu. A configuration window for Tree Transform will open. The first screen is the Layout Builder screen. This is where we can create or delete fields, change their name or data types, mark any field as a variable or attach an expression to a field.

![Untitled Project1f2a39c.autosave](tree-transform.assets/Untitled Project1f2a39c.autosave-1593152207933.gif)

2. Create a new field under the parent node. Let’s name it LateOrders.


3. Click Next and you will be directed to a Layout Modifications window.


4. Select the LateOrders field. Here you can modify any field by applying expressions on it.


5. Write the expression that counts the number of late arriving orders.

Click “…” next to the expression box to open the Expression Builder where you can make use of the extensive library of built-in functions and expressions.


This creates the field values for LateOrders based on the field values of RequiredDate and ShippedDate fields.

6. Click on Orders node and a panel (Options for Collection) will appear. These options are only available for collection nodes.


Options for Collection:

  • Show – shows collection node in Tree Transform object.
  • Flatten With Item Count – flattens data based on the record count in the collection node against each item in the parent node.
  • Flatten Based on Rules – flattens a part of hierarchical data based on predefined rules.
  • Route Based on Rules – routes and creates subsets of data based on predefined rules.
  • Merge With Item Count – merges data based on the record count in the collection node against each item in the parent node.
  • Hide – hides collection node from the Tree Transform object.
  • Calculation Formula – an expression box used for writing rules to route or flatten hierarchical data.
  • Sort Based On Keys – sorts hierarchical data based on the field in the collection node. Only available for Show and Flatten With Item Count options.

This is where we will specify the rule for routing late arriving orders. Select Route Based on Rules and a new section for adding rules will appear on the screen.


7. Add a new rule by clicking on Add switch condition icon 9_icon.

Now, write an expression to route late arriving orders and name this rule ‘LateArrivals.’


8. Click OK. Now observe that a new collection node Orders_LateArrivals has been added to the Tree Transform object.


To preview data, right-click on the header of the transformation object and select Preview Output from the context menu.


A Data Preview window will open. On expanding the records, you will get corresponding order details and appended details of late arriving orders.


To store the output for late arriving orders, you can write it to a destination file or use that data further in the dataflow.

This concludes using the Tree Transformation in Astera Centerprise.