← parentheses operator page · general/parentheses/comp/precedence_in_calc

Precedence in calc 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

Parentheses on components inside calc: (Me_1 + 2) * 3 adds before it multiplies.

Manual:

Parentheses: "The operations enclosed in the parentheses are evaluated first", with ( CMP_1 - CMP_2 ) among the valid syntaxes and op of type dataset | component | scalar.

Expected:

Me_2 is (1 + 2) * 3 = 9 and (4 + 2) * 3 = 18, Integers; without the parentheses the multiplication would come first and give 7 and 10.

script.vtl ⇩

DS_r := DS_1[calc Me_2 := (Me_1 + 2) * 3];

input/DS_1.csv ⇩

Id_1Me_1
11
24

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
119
2418

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