The Flattener
The Flattener element "flattens" hierarchical data into a simpler, tabular set of rows and columns, making the information usable for a variety of Logi elements.
- About the Flattener
- Attributes
- Usage Examples
About the Flattener
Some data sources return information in hierarchical formats, which may contain
multiple levels of parent-child relationships. This structure can create difficulties
for further processing, display, and consumption. The Flattener element processes hierarchical data into a tabular set of rows and columns, so that it can be used with a range of other Logi elements.
The Flattener is available for use with a limited number of datalayers, including:
- DataLayer.JSON File
- DataLayer.Mongo Find
- DataLayer.Mongo Map Reduce
- DataLayer.Mongo Run Command
- DataLayer.REST
- DataLayer.Web Service
- DataLayer.XML File
Attributes
The attributes for the Flattener element are described below:
Attribute | Description |
---|---|
Bottom Level Element Name | Specifies the name of the element where the flattening operation should end. Any element with this name will not have any of its children processed. The default (no value) causes flattening to end at the lowest child level. |
ID | A unique element ID. |
Prepend Element Names | Specifies whether the element name should be prepended to the attribute when it's flattened. For example, if set to True (the default value), <parent child="x" /> will be output as <datalayerid parent_child="x" />. If set to False, it would be output as <datalayerid child="x" />. |
Top Level XPath | Specifies an XPath query to be used to select the portion of the dataset to be flattened. The default value is *, which selects the entire dataset. |
The effects of these attributes on data are shown in examples in the next section.
Usage Examples
1. Here's a simple example of flattening an entire data set:
|
Consider the hierarchical dataset shown above.
<datalayerid hasTrunk="true" id="1" CommonName="Red Oak" Species="Quercus rubra" /> <datalayerid hasTrunk="true" id="2" CommonName="White Oak" Species="Quercus alba" /> <datalayerid hasTrunk="false" id="1" CommonName="Broccoli" Species="Brassica oleracea" /> |
Applying the Flattener element transposes the data into a tabular layout, as shown above. Note that text node elements are treated the same way as attributes.
2. Using the same original data, this example provides a starting point for the flattening process:
<datalayerid hasTrunk="true" id="1" CommonName="Red Oak" Species="Quercus rubra" /> <datalayerid hasTrunk="true" id="2" CommonName="White Oak" Species="Quercus alba" /> |
The flattened data shown above is created by specifying a Top Level XPath attribute value: Plants/Trees.
3. Using the same original data, this is an example of a case where nested elements could have the same attribute names but having
different meanings:
|
In these cases, setting the Flattener element's Prepend Element Names attribute to True produces the output shown above.
4. You also specify an ending point, so that only a portion of the hierarchical data is processed, and combine attributes to further limit processing:
<datalayerid hasTrunk="true" /> |
For example, setting the Top Level XPath attribute to Plants/Trees and the Bottom Level Element Name attribute to Trees, produces the output shown above.