Pivot
In this article
Overview
You can use this Snap to convert selected columns in the input document to the rows in the output document.
Snap Type
Pivot Snap is a Transform-type Snap that transforms the selected fields by shifting the selected field names and their values to values of a target field and target value field, respectively.
Prerequisites
None.
Support for Ultra Pipelines
Works in Ultra Pipelines.Â
Limitations and Known Issues
None.
Snap Views
Type | Format | Number of Views | Examples of Upstream and Downstream Snaps | Description |
---|---|---|---|---|
Input | Document |
|
| Documents with nested or flat map data. |
Output | Document |
|
| Stream of documents with pivoted map data and the pivoted fields. |
Error | Error handling is a generic way to handle errors without losing data or failing the Snap execution. You can handle the errors that the Snap might encounter while running the Pipeline by choosing one of the following options from the When errors occur list under the Views tab:
Learn more about Error handling in Pipelines. |
Snap Settings
Asterisk ( * ): Indicates a mandatory field.
Suggestion icon (): Indicates a list that is dynamically populated based on the configuration.
Expression icon ( ): Indicates the value is an expression (if enabled) or a static value (if disabled). Learn more about Using Expressions in SnapLogic.
Add icon ( ): Indicates that you can add fields in the fieldset.
Remove icon ( ): Indicates that you can remove fields from the fieldset.
Field Name | Field Type | Field Dependency | Description | |
---|---|---|---|---|
Label* Â Default Value:Â Pivot | String | None. | Specify a unique name for the Snap. Â | |
Selected Fields | Use this fieldset to select fields to be pivoted or remain unchanged in the output document based on the value of the Treat selected fields as static checkbox. | |||
Selected Field Default Value: N/A | String/Suggestion | None. | Specify or select the field to be included in the action. | |
If Field Absent Default Value: N/A | Dropdown list | None. | Select one of the following options to apply for the selected field:
| |
Treat selected fields as static  Default Value: Deselected | Checkbox | None. | Select this checkbox to treat selected fields as static in the output document. Selecting this checkbox enables the following fields:
Selecting this checkbox affects the processing of the input documents and preserves the structure of the selected fields when the remaining fields are pivoted. | |
Target Pivoted Field* Â Default Value: N/A | String/Suggestion | None. | Specify or select the target pivoted field. | |
Target Pivoted Value* Â Default Value: N/A | String/Suggestion | None. | Specify or select the target pivoted value. | |
No Pivots Target Field Behavior*  Default Value: Substitute null | Dropdown list | Appears when you select the Treat selected fields as static checkbox. | Select one of the following options (behavior) you want to apply on the target fields—by default if no fields remain to be pivoted (all fields selected as static).
| |
No Pivots Target Value Behavior*  Default Value: Substitute null | Dropdown list | Appears when you select the Treat selected fields as static checkbox. | Select one of the following options (behavior) you want to apply on the target fields—by default if no fields remain to be pivoted (all fields selected as static).
| |
Target field full path  Default Value: Deselected | Checkbox | Appears when you deselect Treat selected fields as static checkbox. | Select this checkbox to include the target field as a full path when the Pivot field property value is nested. | |
Snap Execution Default Value:Â | Dropdown list | N/A | Select one of the following three modes in which the Snap executes:
|
Troubleshooting
Error | Reason | Resolution |
---|---|---|
If a Selected Field has a space in the name, an error is displayed and the Snap fails. | The Selected field does not support empty spaces. | Enclose the field value in braces and single quotes ( [' ']). For example, |
Invalid default behavior for pivoted target field and target value. | Behavior for one of the Target field or Target value fields cannot be | Select Ignore behavior or non-Ignore behavior for both target field and target value and retry |
Examples
Behavior of Pivot Snap when the Treat selected fields as static checkbox is Deselected
This example Pipeline demonstrates the expected behavior of Pivot Snap when the Treat selected fields as static checkbox is deselected (default option).
First, configure the CSV Generator Snap with the data as shown in the image.
On validating, the Snap generates the output as follows.
Next, configure the Pivot Snap to substitute null values for the selected fields ($['2010'], $['2012'], $['2014'], $['2016'],$['2019'],$['2020']
) and deselect Treat selected fields as static checkbox.
On validating the Snap, the Snap returns all the fields in the output as per the configured behavior for the Selected fields.
Behavior of Pivot Snap when the Treat selected fields as static Checkbox is Selected
Scenario 1: Selected fields are present in the input document
This example Pipeline demonstrates the behavior of the Pivot Snap on the selected fields when you apply Substitute empty strings and Null values on the target fields, but the selected fields exist in the input document.
First, configure the CSV Generator Snap with the data as shown in the image.
On validating, the Snap generates the output as follows.
Next, configure the Pivot Snap as follows:
Selected Fields
$Name
: If this field does not exist, the Snap substitutes an empty string for this field in the output.$[Last Date Available'
]: If this field does not exist, the Snap substitutes null value for this field in the output.
Select the Treat selected fields as static checkbox.
On validating, the Snap generates the output as per the configured behavior for the Selected fields. That is, the Snap generates values for all the fields because the selected fields exist originally in the input document.
Scenario 2: Selected fields are absent in the input document
This example Pipeline demonstrates the behavior of the Pivot Snap of the selected fields when you apply all the available options (Ignore, Substitute null, Substitute empty string, Substitute zero) on the target fields and the selected fields do not exist in the input document.
First, configure the CSV Generator Snap with the data as shown in the image.
On validating, the Snap generates the output as follows.
First, configure the CSV Generator Snap with the data as shown in the image. On validating, the Snap generates the output as follows.
Selected Fields
$Field01
—If this field does not exist, the Snap ignores and does not return anything in the output.$Field02
—If this field does not exist, the Snap substitutes null value in the output.$Field03
—If this field does not exist, the Snap substitutes an empty string in the output.$Field04
—If this field does not exist, the Snap substitutes zero in the output.
Select the Treat selected fields as static checkbox.
On validating the Snap, the Snap generates the output as per the configured behavior for the Selected fields.
Scenario 3: Selected fields are nested in the input document
This example Pipeline demonstrates the behavior of the Pivot Snap on the selected fields when they are nested in the input document.
First, configure the JSON Generator Snap with the data as shown in the image.
On validating, the Snap generates the output as follows.
Next, configure the Pivot Snap as follows:
Selected Fields
$StudentName
: If this field is absent, the Snap substitutes an empty string in its value in the output.$Class
: If this field is absent, the Snap substitutes zero in the output..$Math.Stats
: This is a nested field and the Snap substitutes a null value in the output.$Math.Quants
: This is a nested field and the the Snap ignores it.
Select the Treat selected fields as static checkbox.
On validating the Snap, the Snap extracts the nested fields (that were included in the Selected fields) to the root level and leaves the remaining nested fields outside the root level.
Downloads
Snap Pack History
Related Links
Community Post: Video: SnapLogic Generic Pivot Demo
Â
Have feedback? Email documentation@snaplogic.com | Ask a question in the SnapLogic Community
© 2017-2024 SnapLogic, Inc.