← calc operator page · clause/calc/measure_default/new_component_is_measure

New component is measure 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

calc Me_2 := Me_1 * 2 with no role: Me_2 is not in DS_1.

Manual:

Calculation of a Component: "When the role is omitted, the following rule is applied: ... if the component does not exist in the operand Data Set then its role is Measure", and "If the calculated Component is a new Component, it is added to the output Data Set".

Expected:

Id_1 and Me_1, plus the Measure Me_2 = 20, 40 and 60, an Integer as Me_1 * 2 is in Manual example 1. Manual example 1 covers the other half of the rule, an existing measure, and Existing attribute keeps role an existing attribute.

script.vtl ⇩

DS_r := DS_1 [ calc Me_2 := Me_1 * 2 ];

input/DS_1.csv ⇩

Id_1Me_1
110
220
330

input/DS_1.json ⇩

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

expected/DS_r.csv ⇩

Id_1Me_1Me_2
11020
22040
33060

expected/DS_r.json ⇩

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