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

Type

Format

Number of Views

Examples of Upstream and Downstream Snaps

Description

Input 

Document

  • Min: 1

  • Max: 1

  • Mapper

  • Copy

Documents with nested or flat map data.

Output

Document

  • Min: 1

  • Max: 1

  • File Reader

  • Zip File Read

  • Mapper

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:

  • Stop Pipeline Execution: Stops the current Pipeline execution if the Snap encounters an error.

  • Discard Error Data and Continue: Ignores the error, discards that record, and continues with the remaining records.

  • Route Error Data to Error View: Routes the error data to an error view without stopping the Snap execution.

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

Field Name

Field Type

Field Dependency

Description

Label*

 

Default ValuePivot
ExamplePivot contract emps

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
Example: $StudentName

String/Suggestion

None.

Specify or select the field to be included in the action.

If Field Absent

Default Value: N/A
Example: Ignore

Dropdown list

None.

Select one of the following options to apply for the selected field:

  • Ignore

  • Substitute null

  • Substitute empty string

  • Substitute zero

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:

  • No Pivots Target Field Behavior

  • No Pivots Target Value Behavior

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
Example: $Student

String/Suggestion

None.

Specify or select the target pivoted field.

Target Pivoted Value*

 

Default Value: N/A
Example: Score

String/Suggestion

None.

Specify or select the target pivoted value.

No Pivots Target Field Behavior*

 

Default Value: Substitute null
Example: Ignore

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).

  • Ignore

  • Substitute null

  • Substitute empty string

  • Substitute zero

No Pivots Target Value Behavior*

 

Default Value: Substitute null
Example: Ignore

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).

  • Ignore

  • Substitute null

  • Substitute empty string

  • Substitute zero

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
Example: Validate & Execute

Dropdown list

N/A

Select one of the following three modes in which the Snap executes:

  • Validate & Execute: Performs limited execution of the Snap, and generates a data preview during Pipeline validation. Subsequently, performs full execution of the Snap (unlimited records) during Pipeline runtime.

  • Execute only: Performs full execution of the Snap during Pipeline execution without generating preview data.

  • Disabled: Disables the Snap and all Snaps that are downstream from it.

Troubleshooting

Error

Reason

Resolution

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, $['House Rent'] instead of $House Rent.

Invalid default behavior for pivoted target field and target value.

Behavior for one of the Target field or Target value fields cannot be Ignore when the other is not Ignore, and there are no fields available to pivot

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.

Download this Pipeline.


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.

Download this Pipeline.


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.

Download this Pipeline.


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.

Download this Pipeline.


Downloads