← define_operator operator page · definitions/define_operator/component/identifier_in_calc

Identifier in calc 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

a parameter of type identifier<integer>, called inside calc with the Identifier Id_1.

Manual:

define operator: componentRole ::= component | identifier | measure | attribute | viral attribute. The script ends with end operator, as the page's examples and the grammar do; its syntax line writes end define operator.

Expected:

Me_2 = Id_1 * 10, a new Measure that calc adds: (1, 10, 10) and (2, 20, 20).

script.vtl ⇩

define operator times_ten (c identifier<integer>)
    returns component<integer> is
        c * 10
end operator;

DS_r := DS_1[calc Me_2 := times_ten(Id_1)];

input/DS_1.csv ⇩

Id_1Me_1
110
220

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
11010
22020

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