← unpivot operator page · clause/unpivot/basic/manual_ex_1

Manual example 1 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

unpivot Id_2, Me_1, on the Integer measures A, B and C.

Manual:

Unpivoting, Example 1, output verbatim: "The VDS identifier is assigned a value equal to the name of the Measure M of op", and "The VDS measure is assigned a value equal to the value of the Measure M of op".

Expected:

Six data points, one per data point and measure: Id_2 holds A, B or C and Me_1 its value, such as (1, A) = 5 and (2, C) = 9.

script.vtl ⇩

DS_r := DS_1 [ unpivot Id_2, Me_1 ];

input/DS_1.csv ⇩

Id_1ABC
1527
2349

input/DS_1.json ⇩

{
  "datasets": [
    {
      "name": "DS_1",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
        {"name": "A", "type": "Integer", "role": "Measure", "nullable": true},
        {"name": "B", "type": "Integer", "role": "Measure", "nullable": true},
        {"name": "C", "type": "Integer", "role": "Measure", "nullable": true}
      ]
    }
  ]
}

expected/DS_r.csv ⇩

Id_1Id_2Me_1
1A5
2A3
1B2
2B4
1C7
2C9

expected/DS_r.json ⇩

{
  "datasets": [
    {
      "name": "DS_r",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier"},
        {"name": "Id_2", "type": "String", "role": "Identifier"},
        {"name": "Me_1", "type": "Integer", "role": "Measure"}
      ]
    }
  ]
}