← calc operator page · clause/calc/identifier/new_identifier_from_measure

New identifier from measure 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

calc identifier Id_2 := Me_1: a new identifier with the values of the String measure Me_1, which DS_1 declares non-nullable.

Manual:

Calculation of a Component: "The operator calculates new Identifier, Measure or Attribute Components on the basis of sub-expressions at Component level", and "If the calculated Component is a new Component, it is added to the output Data Set".

Expected:

Id_2 is added next to Id_1, with A and B; Me_1 and Me_2 are unchanged. By the team decision of #1010, calc identifier raises SemanticError 1-1-1-16 over an expression declared nullable, whatever the data (intended), and 2-1-1-16 when a null reaches a non-nullable one at run time: Me_1 is declared non-nullable, the form that the manual and the decision both accept, and the decision does not change this output.

script.vtl ⇩

DS_r := DS_1 [ calc identifier Id_2 := Me_1 ];

input/DS_1.csv ⇩

Id_1Me_1Me_2
1A10
2B20

input/DS_1.json ⇩

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

expected/DS_r.csv ⇩

Id_1Id_2Me_1Me_2
1AA10
2BB20

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": "String", "role": "Measure"},
        {"name": "Me_2", "type": "Integer", "role": "Measure"}
      ]
    }
  ]
}