Skip to main content

Unpivot

Reshape data from wide format to long format by turning columns into rows (also known as "melt").

Sockets

SocketDirectionDescription
inputInputData to unpivot
outputOutputUnpivoted (long-format) data

How Unpivot Works

Unpivot takes a "wide" table and makes it "tall":

Before (wide format):

RegionSalesCosts
North10080
South15090

After unpivoting (on: Sales, Costs, index: Region):

Regionvariablevalue
NorthSales100
NorthCosts80
SouthSales150
SouthCosts90

Configuration

OptionDefaultDescription
Unpivot Columns(required)Columns to turn into rows
Keep Columns(optional)Columns to preserve as row identifiers
Variable NamevariableName for the column that stores original column names
Value NamevalueName for the column that stores the values

Each input row produces N output rows, where N is the number of unpivot columns. For example, unpivoting 5 columns from a 1,000-row table produces 5,000 output rows.

Column Selection

For each input column, you can choose to:

  • Unpivot it (its values become rows)
  • Keep it (preserved as an identifier in every output row)
  • Neither (dropped from output)

A column cannot be both unpivoted and kept.

Safety Checks

Sigilweaver Loom checks the potential output size before executing to prevent accidental row explosion. The limit is configurable via SAFETY_MAX_UNPIVOT_ROWS (default: 100,000,000).

Examples

Monthly Columns to Rows

Given a table with product, jan, feb, mar columns:

  1. Set columns jan, feb, mar to Unpivot
  2. Set product to Keep
  3. Set Variable Name to month
  4. Set Value Name to sales

Result:

productmonthsales
Widgetjan100
Widgetfeb120
Widgetmar110
.........

Notes

  • Unpivot is a streaming operation - it does not need to load all data before producing output
  • If all unpivot columns share the same data type, the value column inherits that type; otherwise it becomes String
  • Use Pivot to reverse an unpivot operation
  • The variable column is always of type String