The Tree Transform object 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 the Tree Transform object in Astera Centerprise.
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 object.
Using Tree Transform¶
1. To get a Tree Transform object from the Toolbox, go to Toolbox > Transformations > Tree Transform and drag-and-drop the Tree Transform object onto the designer.
The transformation object is empty right now. This is because we have not 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 window is the Layout Builder window. This is where we can create or delete fields, change their name or data types, mark any field as a variable or attach expressions to fields.
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 to 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 in Centerprise.
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 theTree 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. A new section for adding rules will appear in the window.
7. Add a new rule by clicking on the Add switch condition 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 Transform transformation object in Astera Centerprise.