Nvl · nvl
---
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
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
TimePeriodtype is writtenTime_Period, as vtlengine does.- Expected:
Me_1is 0 for S and N, where it is null, and unchanged for the other four.
DS_r := nvl ( DS_1, 0 );
| Id_1 | Id_2 | Id_3 | Id_4 | Me_1 |
|---|---|---|---|---|
| 2012 | B | Total | Total | 11094850 |
| 2012 | G | Total | Total | 11123034 |
| 2012 | S | Total | Total | |
| 2012 | M | Total | Total | 417546 |
| 2012 | F | Total | Total | 5401267 |
| 2012 | N | Total | Total |
| Id_1 | Id_2 | Id_3 | Id_4 | Me_1 |
|---|---|---|---|---|
| 2012 | B | Total | Total | 11094850 |
| 2012 | G | Total | Total | 11123034 |
| 2012 | S | Total | Total | 0 |
| 2012 | M | Total | Total | 417546 |
| 2012 | F | Total | Total | 5401267 |
| 2012 | N | Total | Total | 0 |
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 inDS_1and id 4 only inDS_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_1and takesDS_2’s 200; id 3 keeps its 30, andDS_2’s 300 is not used.
DS_r := nvl ( DS_1, DS_2 );
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | |
| 3 | 30 |
| Id_1 | Me_1 |
|---|---|
| 2 | 200 |
| 3 | 300 |
| 4 | 400 |
| Id_1 | Me_1 |
|---|---|
| 2 | 200 |
| 3 | 30 |
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 ofnvltakes only a Scalar second one.
DS_r := nvl ( 5, DS_1 );
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | |
| 3 | 30 |
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 )insidecalc: a component and a scalar. The new measureMe_2is added andMe_1is 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_2is 10, 0 and 30: the nullMe_1of id 2 becomes 0 inMe_2and stays null inMe_1.
DS_r := DS_1[calc Me_2 := nvl ( Me_1, 0 )];
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | |
| 3 | 30 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 10 | 10 |
| 2 | 0 | |
| 3 | 30 | 30 |
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 )insidecalc: two components of the same data set, with a nullMe_1and, in one data point, a nullMe_2as 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_3is 10, 200 and null:Me_1is kept where it is not null; where it is null the result isMe_2, which is null at id 3.
DS_r := DS_1[calc Me_3 := nvl ( Me_1, Me_2 )];
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 10 | 100 |
| 2 | 200 | |
| 3 |
| Id_1 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|
| 1 | 10 | 100 | 10 |
| 2 | 200 | 200 | |
| 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 )insidecalc: 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 ofnvltakes only a Scalar second one.
DS_r := DS_1[calc Me_2 := nvl ( 5, Me_1 )];
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | |
| 3 | 30 |
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 )withSC_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.
SC_r := nvl ( null, SC_1 );
| SC_1 |
|---|
| 0 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
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 )withSC_1= 5 andSC_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.
SC_r := nvl ( SC_1, SC_2 );
| SC_1 | SC_2 |
|---|---|
| 5 | 0 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗