← sub operator page · clause/sub/one_id/manual_ex_3

Manual example 3 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

DS_1 [ sub Id_2 = "A" ] + DS_1 [ sub Id_2 = "B" ]: two subspaces on one identifier, added.

Manual:

Subspace, Example 3, output verbatim: "It maintains the Data Points of VDS for which identifier = value", then "It projects out (“drops”, in VTL terms) all the identifier (s)".

Expected:

Both subspaces have Id_1 and Id_3, and the sum pairs their data points on them: (1,XX) = 20 + 4 = 24, (1,YY) = 10, (2,XX) = 19 and (2,YY) = 20. At_1 is non-viral, so the sum does not keep it: "the non-viral Attributes are not kept in the result" (User Manual).

script.vtl ⇩

DS_r := DS_1 [ sub Id_2 = "A" ] + DS_1 [ sub Id_2 = "B" ];

input/DS_1.csv ⇩

Id_1Id_2Id_3Me_1At_1
1AXX20F
1AYY1F
1BXX4E
1BYY9F
2AXX7F
2AYY5E
2BXX12F
2BYY15F

input/DS_1.json ⇩

{
  "datasets": [
    {
      "name": "DS_1",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
        {"name": "Id_2", "type": "String", "role": "Identifier", "nullable": false},
        {"name": "Id_3", "type": "String", "role": "Identifier", "nullable": false},
        {"name": "Me_1", "type": "Integer", "role": "Measure", "nullable": true},
        {"name": "At_1", "type": "String", "role": "Attribute", "nullable": true}
      ]
    }
  ]
}

expected/DS_r.csv ⇩

Id_1Id_3Me_1
1XX24
1YY10
2XX19
2YY20

expected/DS_r.json ⇩

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