Nvl · nvl

🟢 7 of 7 forms all ok · VTL 2.2 Reference Manual ↗ · vtlengine 1.10.0rc2 (90ee9376) · 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["Nvl · nvl<br/>🟢7"]:::ok
    subgraph G_ds["Dataset"]
        direction LR
        v_ds_sc["nvl(DS, sc)"]:::ok
        v_ds_ds["nvl(DS, DS)"]:::ok
        v_sc_ds["nvl(sc, DS)"]:::ok
    end
    subgraph G_comp["Component"]
        direction LR
        v_comp_sc["nvl(comp, sc)"]:::ok
        v_comp_comp["nvl(comp, comp)"]:::ok
        v_sc_comp["nvl(sc, comp)"]:::ok
    end
    subgraph G_sc["Scalar"]
        direction LR
        v_sc_sc["nvl(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_sc href "#form-ds-sc"
    click v_ds_ds href "#form-ds-ds"
    click v_sc_ds href "#form-sc-ds"
    click v_comp_sc href "#form-comp-sc"
    click v_comp_comp href "#form-comp-comp"
    click v_sc_comp href "#form-sc-comp"
    click v_sc_sc href "#form-sc-sc"
    

Types

Takes any scalar · Gives any type

Viral attributes: combined with the propagation rules → Viral propagation

Comes from: any operator that returns a value

Goes to: whatever takes its input's type

Forms

nvl(DS, sc) 🟢 · any scalar → any type

Manual example 1 🟢 pandas ✅ · DuckDB ✅
Tests:

nvl ( DS_1, 0 ) on a data set: each null measure value becomes 0.

Manual:

Nvl, Example 1, output verbatim: “The operator nvl returns the value from op2 when the value from op1 is null, otherwise it returns the value from op1.” The page’s TimePeriod type is written Time_Period, as vtlengine does.

Expected:

Me_1 is 0 for S and N, where it is null, and unchanged for the other four.

script.vtl
DS_r := nvl ( DS_1, 0 );
Input DS_1
Id_1Id_2Id_3Id_4Me_1
2012BTotalTotal11094850
2012GTotalTotal11123034
2012STotalTotal
2012MTotalTotal417546
2012FTotalTotal5401267
2012NTotalTotal
Expected DS_r
Id_1Id_2Id_3Id_4Me_1
2012BTotalTotal11094850
2012GTotalTotal11123034
2012STotalTotal0
2012MTotalTotal417546
2012FTotalTotal5401267
2012NTotalTotal0

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

nvl(DS, DS) 🟢 · any scalar → any type

Partly different identifiers 🟢 pandas ✅ · DuckDB ✅
Tests:

nvl ( DS_1, DS_2 ) on two data sets with the same components and partly different identifiers: id 1 is only in DS_1 and id 4 only in DS_2.

Manual:

Nvl: “The operator has the typical behaviour of the operators applicable on two scalar values or Data Sets or Data Set Components”, where “Data Points that are not coupled are left out” (Typical behaviours).

Expected:

only ids 2 and 3 are coupled: id 2 is null in DS_1 and takes DS_2’s 200; id 3 keeps its 30, and DS_2’s 300 is not used.

script.vtl
DS_r := nvl ( DS_1, DS_2 );
Input DS_1
Id_1Me_1
110
2
330
Input DS_2
Id_1Me_1
2200
3300
4400
Expected DS_r
Id_1Me_1
2200
330

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 ↗

nvl(sc, DS) 🟢 · any scalar → any type

Non null scalar first operand 🟢 pandas ✅ · DuckDB ✅
Tests:

nvl ( 5, DS_1 ): a scalar as op1 and a data set as op2.

Manual:

Nvl: “The operator has the typical behaviour of the operators applicable on two scalar values or Data Sets or Data Set Components”; there “DS_1 or DS_2 may be replaced by a Scalar value”, and “An operand Scalar value is treated as a Data Point that couples with all the Data Points of the other operand” (Typical behaviours).

Expected:

the error 1-1-9-2, “At op {op}: The applicable operand cannot be a {right_type} when the operand is a {left_type}”: by a team decision, a Scalar first operand of nvl takes only a Scalar second one.

script.vtl
DS_r := nvl ( 5, DS_1 );
Input DS_1
Id_1Me_1
110
2
330

Expected error 1-1-9-2: At op {op}: The applicable operand cannot be a {right_type} when the operand is a {left_type}.

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

nvl(comp, sc) 🟢 · any scalar → any type

Null replaced by zero 🟢 pandas ✅ · DuckDB ✅
Tests:

nvl ( Me_1, 0 ) inside calc: a component and a scalar. The new measure Me_2 is added and Me_1 is left as it is.

Manual:

Nvl: “The operator nvl returns the value from op2 when the value from op1 is null, otherwise it returns the value from op1.”

Expected:

Me_2 is 10, 0 and 30: the null Me_1 of id 2 becomes 0 in Me_2 and stays null in Me_1.

script.vtl
DS_r := DS_1[calc Me_2 := nvl ( Me_1, 0 )];
Input DS_1
Id_1Me_1
110
2
330
Expected DS_r
Id_1Me_1Me_2
11010
20
33030

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

nvl(comp, comp) 🟢 · any scalar → any type

Second component fills nulls 🟢 pandas ✅ · DuckDB ✅
Tests:

nvl ( Me_1, Me_2 ) inside calc: two components of the same data set, with a null Me_1 and, in one data point, a null Me_2 as well.

Manual:

Nvl: “The operator nvl returns the value from op2 when the value from op1 is null, otherwise it returns the value from op1.”

Expected:

Me_3 is 10, 200 and null: Me_1 is kept where it is not null; where it is null the result is Me_2, which is null at id 3.

script.vtl
DS_r := DS_1[calc Me_3 := nvl ( Me_1, Me_2 )];
Input DS_1
Id_1Me_1Me_2
110100
2200
3
Expected DS_r
Id_1Me_1Me_2Me_3
11010010
2200200
3

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

nvl(sc, comp) 🟢 · any scalar → any type

Non null scalar first operand 🟢 pandas ✅ · DuckDB ✅
Tests:

nvl ( 5, Me_1 ) inside calc: a scalar as op1 and a component as op2.

Manual:

Nvl: “The operator nvl returns the value from op2 when the value from op1 is null, otherwise it returns the value from op1.” Its operands are typed op1 :: dataset | component | scalar, and the Typical behaviours apply an operator “on a Component and a Scalar value”.

Expected:

the error 1-1-9-2, “At op {op}: The applicable operand cannot be a {right_type} when the operand is a {left_type}”: by a team decision, a Scalar first operand of nvl takes only a Scalar second one.

script.vtl
DS_r := DS_1[calc Me_2 := nvl ( 5, Me_1 )];
Input DS_1
Id_1Me_1
110
2
330

Expected error 1-1-9-2: At op {op}: The applicable operand cannot be a {right_type} when the operand is a {left_type}.

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

nvl(sc, sc) 🟢 · any scalar → any type

Null first operand 🟢 pandas ✅ · DuckDB ✅
Tests:

nvl ( null, SC_1 ) with SC_1 = 0: a null first operand on scalars.

Manual:

Nvl: “nvl ( null, 0 ) returns 0”.

Expected:

SC_r = 0, an Integer: op1 is null, so the result is op2.

script.vtl
SC_r := nvl ( null, SC_1 );
Input scalars
SC_1
0
Expected scalars

Name

Type

Value

SC_r

Integer

"0"

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

Non null first operand 🟢 pandas ✅ · DuckDB ✅
Tests:

nvl ( SC_1, SC_2 ) with SC_1 = 5 and SC_2 = 0: a first operand that is not null.

Manual:

Nvl: “nvl ( 5, 0 ) returns 5”.

Expected:

SC_r = 5, an Integer: op1 is not null, so it is the result.

script.vtl
SC_r := nvl ( SC_1, SC_2 );
Input scalars
SC_1SC_2
50
Expected scalars

Name

Type

Value

SC_r

Integer

"5"

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