Transformation - Grouping

Last modified by Danniar Firdausy on 2024/09/17 09:57

In this microlearning, we will explore the grouping functionality, which allows you to organize data based on specific criteria, ensuring efficient and customized transformations. Before diving into the details of grouping functionality within eMagiz's transformation tooling, it's important to understand the basic concepts covered in the crash course.

Should you have any questions, please get in touch with academy@emagiz.com.

1. Prerequisites

  • Basic knowledge of the eMagiz platform

2. Key concepts

This microlearning focuses on the grouping functionality that eMagiz offers as part of the transformation.

  • With grouping we mean: The functionality that groups a list based on one or more specific criteria.

3. Transformation - Grouping

This provides several options for organizing a list of source entities into groups within the transformation tooling. The groups are created based on shared values of a grouping key or a pattern that specifies the start of a new group.

There are three options you have to group parts of your output:

  • Group By
  • Starting With
  • Use Current Group
Information

Note that you can use this operation combined with a Filter operation to restrict the source elements you want to group.

To activate the grouping functionality, press the + icon in front of the list entity (in my case, "Design"). Here, you have the custom snippet, filter, and group option (from left to right)

intermediate-create-your-transformations-grouping--operations-on-entity.png

Once you have selected the group option, a pop-up will appear containing three options. Each of these options is discussed below.

intermediate-create-your-transformations-grouping--grouping-popup.png
  

3.1 Group By

If the option Group By is selected, the groups will be created based on the selected Key attribute. If your grouping-key is complex, select Custom Key and write a custom XPath expression. In the dropdown menu, you can choose all attributes belonging to the input list or the [Custom Key] option. Selecting the second option allows you to specify your own XPath to get the correct value on which to base your grouping logic.

intermediate-create-your-transformations-grouping--grouping-popup-dropdown.png

3.2 Starting With

The option Starting with allows you to write an XPath expression specifying the start of a new group. Start with an expression, an attribute, or an entity from your source list. From that point, every item goes into the new group until another element matches the condition.

For example, if your source file contains HTML, where h1 describes the name of a book chapter and the following p elements, describe a chapter summary. You could use this operation to start a new group for each h1 found and add them to a chapter element. Example of the output of such an XML structure:

  <chapters>
   <chapter>
   <h1>Chapt1</h1>
   <p>summary 1</p>
   </chapter>
   <chapter>
   <h1>Chapt2</h1>
   <p>summary 2</p>
  </chapter>
 </chapters>

3.3 Current Group

When you want to create a group within a group, you should utilize this functionality to achieve this. This is only used in very complex cases and is quite difficult to use. So we strongly advise testing this scenario in particular very thoroughly.

Information

Note that when there is no current group, eMagiz will inform you about this to avoid that you break the transformation functionality within your flow.
 
intermediate-create-your-transformations-grouping--current-group-without-a-parent-group.png

If you already have a group to start with, you will see the following pop-up, which determines the logic of the current group.

intermediate-create-your-transformations-grouping--current-group-with-a-parent-group.png

4. Key takeaways

eMagiz offers three distinct options for grouping data within transformations:

  • Group By: Use this option to group data based on a specific key attribute or a custom XPath expression when more complex logic is required.
  • Starting With: Ideal for creating new groups based on a starting condition, such as when a specific element or pattern in the data is detected.
  • Use Current Group: This advanced option allows you to create subgroups within existing groups, suitable for complex transformations that involve nested data.

You can pair grouping with other transformation operations, like filtering, to fine-tune which elements are grouped, enhancing control and flexibility.

5. Suggested Additional Readings

If you are interested in this topic and want more information on it please read the help text provided by eMagiz and read the following links: