Parentheses · ( )

🟢 3 of 3 forms all ok · VTL 2.2 Reference Manual ↗ · vtlengine 1.10.0rc3 (9e1c81a6) · pandas 2.3.3 · DuckDB 1.5.5
🟢 all ok🟡 partially implemented🛡️ refused with an error🔴 not implemented or crash🔵 engines differ ✅ match · ❌ wrong result · 🛡 guarded error (code) · 💥 crash · 📌 team decision
Dataset formsComponent formsScalar forms
        ---
config:
  flowchart:
    useMaxWidth: false

---
flowchart TB
    classDef ok fill:#d4edda,stroke:#28a745,color:#000
    classDef partial fill:#fff3cd,stroke:#ffc107,color:#000
    classDef refused fill:#d4edda,stroke:#28a745,stroke-width:3px,stroke-dasharray: 2 2,color:#000
    classDef missing fill:#f8d7da,stroke:#dc3545,color:#000
    classDef diverge fill:#cce5ff,stroke:#007bff,color:#000
    classDef block fill:#2b3a4a,stroke:#2b3a4a,color:#fff,font-weight:bold
    classDef ext fill:#fff,stroke:#666,color:#000,stroke-dasharray: 5 5
    O["Parentheses · ( )<br/>🟢3"]:::ok
    subgraph G_ds["Dataset"]
        direction LR
        v_ds["(DS)"]:::ok
    end
    subgraph G_comp["Component"]
        direction LR
        v_comp["(comp)"]:::ok
    end
    subgraph G_sc["Scalar"]
        direction LR
        v_sc["(sc)"]:::ok
    end
    O --- G_ds
    O --- G_comp
    O --- G_sc
    style G_ds fill:#f8f9fa,stroke:#495057,stroke-width:2px
    style G_comp fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 8 5
    style G_sc fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 2 3
    click v_ds href "#form-ds"
    click v_comp href "#form-comp"
    click v_sc href "#form-sc"
    

Types

Takes any scalar · Gives any type

Comes from: any operator that returns a value

Goes to: whatever takes its input's type

Forms

(DS) 🟢 · any scalar → any type

Manual example 1 🟢 pandas ✅ · DuckDB ✅
Tests:

(DS_1 + DS_2) * DS_2: the sum in the parentheses comes first, then the product with DS_2, on the data points that the operands share.

Manual:

Parentheses, Example 1, output verbatim: “The part of the expression inside the parentheses is evaluated before the part outside of the parentheses.”

Expected:

Only (10, A) and (11, B) are in both datasets: Me_1 is (5 + 10) * 10 = 150 and (4 + 6) * 6 = 60, an Integer, and Me_2 is (5.0 + 3.0) * 3.0 = 24.0 and (20.3 + 7.0) * 7.0 = 191.1, a Number. Without the parentheses, (10, A) would give 105 and 14.0.

script.vtl
DS_r := (DS_1 + DS_2) * DS_2;
Input DS_1
Id_1Id_2Me_1Me_2
10A55.0
10B210.5
11A312.2
11B420.3
Input DS_2
Id_1Id_2Me_1Me_2
10A103.0
10C116.2
11B67.0
Expected DS_r
Id_1Id_2Me_1Me_2
10A15024.0
11B60191.1

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

(comp) 🟢 · any scalar → any type

Precedence in calc 🟢 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
Id_1Me_1
11
24
Expected DS_r
Id_1Me_1Me_2
119
2418

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

(sc) 🟢 · any scalar → any type

Addition first 🟢 pandas ✅ · DuckDB ✅
Tests:

Parentheses on scalars: (SC_1 + SC_2) * SC_3 with SC_1 = 2, SC_2 = 3 and SC_3 = 4 adds before it multiplies.

Manual:

Parentheses: “For example (2+3)*4 returns 20, instead 2+3*4 returns 14 because the multiplication has higher precedence than the addition.”

Expected:

SC_r = 20, an Integer, as the operands are integers.

script.vtl
SC_r := (SC_1 + SC_2) * SC_3;
Input scalars
SC_1SC_2SC_3
234
Expected scalars

Name

Type

Value

SC_r

Integer

"20"

Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗

Nested parentheses 🟢 pandas ✅ · DuckDB ✅
Tests:

Nested parentheses, ( SC_1 - SC_2 / (SC_3 + SC_4) ) * SC_5 with SC_1 = 20, SC_2 = 10, SC_3 = 2, SC_4 = 3 and SC_5 = 3: the inner ones are evaluated first.

Manual:

Parentheses: “If more parentheses are nested, the inner parentheses are evaluated first, for example ( 20 - 10 / (2 + 3) ) * 3 would give 54.”

Expected:

2 + 3 = 5, 10 / 5 = 2, 20 - 2 = 18 and 18 * 3 = 54: SC_r = 54, a Number, as a division gives a number (Division page) and so does an operation with a number operand (Subtraction and Multiplication pages).

script.vtl
SC_r := ( SC_1 - SC_2 / (SC_3 + SC_4) ) * SC_5;
Input scalars
SC_1SC_2SC_3SC_4SC_5
2010233
Expected scalars

Name

Type

Value

SC_r

Number

"54"

Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗