← calc operator page · clause/calc/attribute/manual_ex_2

Manual example 2 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

calc attribute At_1 := "EP": a new attribute with a constant value.

Manual:

Calculation of a Component, Example 2, output verbatim: "It is possible to specify the role of the calculated Component among measure, identifier, attribute, or viral attribute", and "If the calculated Component is a new Component, it is added to the output Data Set".

Expected:

The input, plus the String Attribute At_1 = EP on its three data points.

script.vtl ⇩

DS_r := DS_1 [ calc attribute At_1:= "EP" ];

input/DS_1.csv ⇩

Id_1Id_2Id_3Me_1
1ACA20
1BCA2
2ACA2

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}
      ]
    }
  ]
}

expected/DS_r.csv ⇩

Id_1Id_2Id_3Me_1At_1
1ACA20EP
1BCA2EP
2ACA2EP

expected/DS_r.json ⇩

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