define viral propagation

🟢 4 of 4 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
        ---
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["define viral propagation<br/>🟢4"]:::ok
    subgraph G_b1["Signature"]
        direction LR
        v_variable["(variable V)"]:::ok
        v_valuedomain["(valuedomain VD)"]:::ok
    end
    subgraph G_b2["Body"]
        direction LR
        v_enumerated["when … then … #91;else …#93;"]:::ok
        v_aggregation["aggregate min #124; max #124; sum #124; avg"]:::ok
    end
    O --- G_b1
    O --- G_b2
    style G_b1 fill:#f8f9fa,stroke:#868e96,stroke-width:1px
    style G_b2 fill:#f8f9fa,stroke:#868e96,stroke-width:1px
    click v_variable href "#form-variable"
    click v_valuedomain href "#form-valuedomain"
    click v_enumerated href "#form-enumerated"
    click v_aggregation href "#form-aggregation"
    

Types

Takes number, value domain, any scalar · Gives viral propagation

Comes from: any operator that returns a value

Comes from · value domain: none

Goes to · viral propagation: none

Applied by

Every operator that propagates viral attributes applies the rules that this definition registers, as the manual says: "e.g., the typical behaviour rules for binary, aggregate, analytic, or join operators". These operators combine viral attributes, and the manual says so for each group:

  • Operators on two data sets: "For each couple (DP_1, DP_2) and for each Attribute that propagates in DP_r, the Attribute value is calculated by applying the proper Attribute propagation algorithm on the values of the Attributes of DP_1 and DP_2" (Typical behaviours of the ML operators)

  • Aggregate invocations: "For invocation at Data Set level, the Attribute propagation rule is applied." (Aggregate invocation)

  • Analytic invocations: "the Attribute propagation rule is applied for every Viral Attribute in the Data Set by combining, for each row, all the Attribute values in the data points present in relative window" (Analytic invocation)

  • The aggr clause: "For all the other Attributes that are defined as viral, the Attribute propagation rule is applied" (Aggregation)

  • Joins: "The other viral attributes, which are present in multiple data sets, are combined by applying the Attribute propagation rule on VDS₁" (Inner Join)

  • Hierarchical roll-up: "The Attribute propagation rule is applied on the groups of Data Points which contribute to the same Data Points of the result" (Hierarchical roll-up)

  • Check hierarchy: "The Attribute propagation rule is applied on each group of Data Points which contributes to the same Data Point of the result" (Check hierarchy)

Applied by — 43 operators in 10 blocks 🟢43
Join operators (4) 🟢4
String operators (2) 🟢2
Numeric operators (5) 🟢5
Comparison operators (7) 🟢7
Boolean operators (3) 🟢3
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (18) 🟢18
Data validation operators (1) 🟢1
Conditional operators (1) 🟢1
Clause operators (1) 🟢1

Forms

Signature

(variable V) 🟢 · any scalar → viral propagation

Conf priority rule 🟢 pandas ✅ · DuckDB ✅
Tests:

a propagation on the variable At_1, the page’s CONF_priority (“the CL_CONF list with C > N > F”), at DS_1 + DS_2.

Manual:

define viral propagation: the variable is “the Represented Variable owning the viral Attribute”, and a unary clause “matches if the specified value is present in the input pair (regardless of what the other value is)”.

Expected:

At_1 C for the pair (C, N), N for (N, F) and F for (F, F) by else, and it stays viral.

script.vtl
define viral propagation VP_1 (variable At_1) is
    when "C" then "C";
    when "N" then "N";
    else "F"
end viral propagation;

DS_r := DS_1 + DS_2;
Input DS_1
Id_1Me_1At_1
110C
220N
330F
Input DS_2
Id_1Me_1At_1
11N
22F
33F
Expected DS_r
Id_1Me_1At_1
111C
222N
333F

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 ↗

Second rule for the variable 🟢 pandas ✅ · DuckDB ✅
Tests:

two propagations, VP_1 and VP_2, on the same variable At_1, before DS_1 + DS_2.

Manual:

define viral propagation: “It is a semantic error to define more than one propagation rule for the same Value Domain or for the same Variable”.

Expected:

the SemanticError 1-3-3-1, “Duplicate viral propagation rule for variable {name}.”, as the page says: “If more than one propagation definition is declared for the same Variable, a semantic error is raised”.

script.vtl
define viral propagation VP_1 (variable At_1) is
    when "C" then "C";
    else "F"
end viral propagation;

define viral propagation VP_2 (variable At_1) is
    when "N" then "N";
    else "F"
end viral propagation;

DS_r := DS_1 + DS_2;
Input DS_1
Id_1Me_1At_1
110C
220N
330F
Input DS_2
Id_1Me_1At_1
11N
22F
33F

Expected error 1-3-3-1: Duplicate viral propagation rule for variable {name}.

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

(valuedomain VD) 🟢 · any scalar, value domain → viral propagation

Inherited from the domain 🟢 pandas ✅ · DuckDB ✅
Tests:

a propagation on the value domain CL_CONF, the page’s CONF_priority, for At_1, which the input structures define on CL_CONF (its type), at DS_1 + DS_2.

Manual:

define viral propagation: “When a propagation rule is declared on a Value Domain it acts as the default for all Attributes using that Value Domain”.

Expected:

At_1 C for the pair (C, N), N for (N, F) and F for (F, F) by else, and it stays viral and defined on CL_CONF.

script.vtl
define viral propagation VP_1 (valuedomain CL_CONF) is
    when "C" then "C";
    when "N" then "N";
    else "F"
end viral propagation;

DS_r := DS_1 + DS_2;
Input DS_1
Id_1Me_1At_1
110C
220N
330F
Input DS_2
Id_1Me_1At_1
11N
22F
33F
Expected DS_r
Id_1Me_1At_1
111C
222N
333F

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 · value_domains/CL_CONF.json · example page ↗

Body

when … then … [else …] 🟢 · any scalar → viral propagation

First clause in order wins 🟢 pandas ✅ · DuckDB ✅
Tests:

unary clauses only, when "N" before when "C", so a pair with N and C gives N.

Manual:

define viral propagation: a unary clause “matches if the specified value is present in the input pair (regardless of what the other value is)”, and “The first matching clause determines the result”.

Expected:

At_1 N for (C, N), C for (C, F) and F for (F, F) by else.

script.vtl
define viral propagation VP_1 (variable At_1) is
    when "N" then "N";
    when "C" then "C";
    else "F"
end viral propagation;

DS_r := DS_1 + DS_2;
Input DS_1
Id_1Me_1At_1
110C
220C
330F
Input DS_2
Id_1Me_1At_1
11N
22F
33F
Expected DS_r
Id_1Me_1At_1
111N
222C
333F

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 ↗

Binary clause before unary 🟢 pandas ✅ · DuckDB ✅
Tests:

the binary when "C" and "M" then "N" after the unary when "M", as in the page’s COMPUTED_missing. Like it, the rule is not associative over three values, which the page asks of a rule, but here it only combines pairs.

Manual:

define viral propagation: “binary clauses (specifying a pair of values) always take precedence over unary clauses”, and a binary clause “matches if the input pair consists of exactly those two values”.

Expected:

At_1 N for (C, M) and (M, C), M for (M, F) and F for (C, C) by else. The page calls the algorithm “reflexive”, but the User Manual’s reflexive law is about one operand, and the page’s own examples turn two equal values into another one (OBS_STATUS_default gives F for (E, E)), so (C, C) gives F as written.

script.vtl
define viral propagation VP_1 (variable At_1) is
    when "M" then "M";
    when "C" and "M" then "N";
    else "F"
end viral propagation;

DS_r := DS_1 + DS_2;
Input DS_1
Id_1Me_1At_1
110C
220M
330M
440C
Input DS_2
Id_1Me_1At_1
11M
22C
33F
44C
Expected DS_r
Id_1Me_1At_1
111N
222N
333M
444F

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 ↗

Names do not change matching 🟢 pandas ✅ · DuckDB ✅
Tests:

the named clauses R_C and R_N and an unnamed else: the page’s CONF_priority with names.

Manual:

define viral propagation: enumeratedClause ::= { ruleName : } when enumerationCondition then vpResult and defaultClause ::= else vpResult.

Expected:

the names take no part in the matching: At_1 C for (C, N), N for (N, F) and F for (F, F), as without names.

script.vtl
define viral propagation VP_1 (variable At_1) is
    R_C : when "C" then "C";
    R_N : when "N" then "N";
    else "F"
end viral propagation;

DS_r := DS_1 + DS_2;
Input DS_1
Id_1Me_1At_1
110C
220N
330F
Input DS_2
Id_1Me_1At_1
11N
22F
33F
Expected DS_r
Id_1Me_1At_1
111C
222N
333F

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 ↗

Else for unlisted pairs 🟢 pandas ✅ · DuckDB ✅
Tests:

when "C" then "C"; else "F".

Manual:

define viral propagation: the default clause is “an optional fallback clause triggered after all other enumerated clauses when none of them matches”.

Expected:

At_1 C for (C, N), and F for (N, N) and (N, A) by else. The page calls the algorithm “reflexive”, but the User Manual’s reflexive law is about one operand, and the page’s own examples turn two equal values into another one (OBS_STATUS_default gives F for (E, E)), so (N, N) gives F as written.

script.vtl
define viral propagation VP_1 (variable At_1) is
    when "C" then "C";
    else "F"
end viral propagation;

DS_r := DS_1 + DS_2;
Input DS_1
Id_1Me_1At_1
110C
220N
330N
Input DS_2
Id_1Me_1At_1
11N
22N
33A
Expected DS_r
Id_1Me_1At_1
111C
222F
333F

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 ↗

Null for unlisted pairs 🟢 pandas ✅ · DuckDB ✅
Tests:

when "C" then "C" with no else.

Manual:

define viral propagation: “If omitted and no enumerated clause matches, NULL is propagated”.

Expected:

At_1 C for (C, N), and null for (N, N) and (N, A). The page calls the algorithm “reflexive”, but the User Manual’s reflexive law is about one operand, and the page’s own examples turn two equal values into another one (OBS_STATUS_default gives F for (E, E)), so (N, N) gives null as written.

script.vtl
define viral propagation VP_1 (variable At_1) is
    when "C" then "C"
end viral propagation;

DS_r := DS_1 + DS_2;
Input DS_1
Id_1Me_1At_1
110C
220N
330N
Input DS_2
Id_1Me_1At_1
11N
22N
33A
Expected DS_r
Id_1Me_1At_1
111C
222
333

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 ↗

Subtraction of two datasets 🟢 pandas ✅ · DuckDB ✅
Tests:

the propagation at DS_1 - DS_2, whose Measure depends on the order of the operands while the propagation does not.

Manual:

the User Manual’s commutative law “holds for every operator, also for non-commutative operations like difference”, and in Typical behaviours “the Attribute value is calculated by applying the proper Attribute propagation algorithm on the values of the Attributes of DP_1 and DP_2”.

Expected:

Me_1 9 and 18; At_1 C for (C, F) by when "C" and F for (F, F) by else.

script.vtl
define viral propagation VP_1 (variable At_1) is
    when "C" then "C";
    else "F"
end viral propagation;

DS_r := DS_1 - DS_2;
Input DS_1
Id_1Me_1At_1
110C
220F
Input DS_2
Id_1Me_1At_1
11F
22F
Expected DS_r
Id_1Me_1At_1
19C
218F

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 ↗

Inner join of two datasets 🟢 pandas ✅ · DuckDB ✅
Tests:

the propagation at inner_join(DS_1, DS_2), where At_1 is viral in both datasets.

Manual:

Inner Join: “The other viral attributes, which are present in multiple data sets, are combined by applying the Attribute propagation rule on VDS₁”.

Expected:

Me_1, Me_2 and one viral At_1: C for (C, F) and F for (F, F).

script.vtl
define viral propagation VP_1 (variable At_1) is
    when "C" then "C";
    else "F"
end viral propagation;

DS_r := inner_join(DS_1, DS_2);
Input DS_1
Id_1Me_1At_1
110C
220F
Input DS_2
Id_1Me_2At_1
11F
22F
Expected DS_r
Id_1Me_1Me_2At_1
1101C
2202F

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 ↗

Sum grouped by identifier 🟢 pandas ✅ · DuckDB ✅
Tests:

the propagation at sum(DS_1 group by Id_1), two data points per group.

Manual:

Aggregate invocation: “For invocation at Data Set level, the Attribute propagation rule is applied”, as for “the unary Operators which aggregate Data Points” (User Manual).

Expected:

Me_1 15 with At_1 C for (C, F), and 7 with F for (F, F).

script.vtl
define viral propagation VP_1 (variable At_1) is
    when "C" then "C";
    else "F"
end viral propagation;

DS_r := sum(DS_1 group by Id_1);
Input DS_1
Id_1Id_2Me_1At_1
1A10C
1B5F
2A3F
2B4F
Expected DS_r
Id_1Me_1At_1
115C
27F

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

Hierarchy with a computed total 🟢 pandas ✅ · DuckDB ✅
Tests:

the propagation at hierarchy(DS_1, HR_1 rule Id_2), with TOTAL = X + Y.

Manual:

Hierarchical roll-up: “The Attribute propagation rule is applied on the groups of Data Points which contribute to the same Data Points of the result”, and the default output computed keeps “only the set of Data Points computed according to the Ruleset”.

Expected:

one TOTAL per Id_1: 10 with At_1 C for (C, F), and 3 with F for (F, F).

script.vtl
define viral propagation VP_1 (variable At_1) is
    when "C" then "C";
    else "F"
end viral propagation;

define hierarchical ruleset HR_1 (variable rule Id_2) is
    TOTAL = X + Y
end hierarchical ruleset;

DS_r := hierarchy(DS_1, HR_1 rule Id_2);
Input DS_1
Id_1Id_2Me_1At_1
1X4C
1Y6F
2X1F
2Y2F
Expected DS_r
Id_1Id_2Me_1At_1
1TOTAL10C
2TOTAL3F

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

aggregate min | max | sum | avg 🟢 · any scalar, number → viral propagation

Min of each pair 🟢 pandas ✅ · DuckDB ✅
Tests:

aggregate min on the Number viral At_1, at DS_1 + DS_2.

Manual:

define viral propagation: “The rule simply names the aggregate function that must collapse the set of operand values to a single result”, and “The semantics of these aggregates follow the standard VTL definitions”.

Expected:

At_1 1.5 for (1.5, 4.0) and 2.0 for (3.0, 2.0); Me_1 11 and 22.

script.vtl
define viral propagation VP_1 (variable At_1) is
    aggregate min
end viral propagation;

DS_r := DS_1 + DS_2;
Input DS_1
Id_1Me_1At_1
1101.5
2203.0
Input DS_2
Id_1Me_1At_1
114.0
222.0
Expected DS_r
Id_1Me_1At_1
1111.5
2222.0

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 ↗

Max of each pair 🟢 pandas ✅ · DuckDB ✅
Tests:

aggregate max on the Number viral At_1, at DS_1 + DS_2.

Manual:

define viral propagation: “The rule simply names the aggregate function that must collapse the set of operand values to a single result”, and “The semantics of these aggregates follow the standard VTL definitions”.

Expected:

At_1 4.0 for (1.5, 4.0) and 3.0 for (3.0, 2.0); Me_1 11 and 22.

script.vtl
define viral propagation VP_1 (variable At_1) is
    aggregate max
end viral propagation;

DS_r := DS_1 + DS_2;
Input DS_1
Id_1Me_1At_1
1101.5
2203.0
Input DS_2
Id_1Me_1At_1
114.0
222.0
Expected DS_r
Id_1Me_1At_1
1114.0
2223.0

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 ↗

Sum of each pair 🟢 pandas ✅ · DuckDB ✅
Tests:

aggregate sum on the Number viral At_1, at DS_1 + DS_2.

Manual:

define viral propagation: “The rule simply names the aggregate function that must collapse the set of operand values to a single result”, and “The semantics of these aggregates follow the standard VTL definitions”.

Expected:

At_1 5.5 for (1.5, 4.0) and 5.0 for (3.0, 2.0); Me_1 11 and 22.

script.vtl
define viral propagation VP_1 (variable At_1) is
    aggregate sum
end viral propagation;

DS_r := DS_1 + DS_2;
Input DS_1
Id_1Me_1At_1
1101.5
2203.0
Input DS_2
Id_1Me_1At_1
114.0
222.0
Expected DS_r
Id_1Me_1At_1
1115.5
2225.0

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 ↗

Avg of each pair 🟢 pandas ✅ · DuckDB ✅
Tests:

aggregate avg on the Number viral At_1, at DS_1 + DS_2.

Manual:

define viral propagation: “The rule simply names the aggregate function that must collapse the set of operand values to a single result”, and “The semantics of these aggregates follow the standard VTL definitions”.

Expected:

At_1 2.75 for (1.5, 4.0) and 2.5 for (3.0, 2.0); Me_1 11 and 22. Over one pair both readings of #1175 give the mean, so no team decision applies, and At_1 is a Number, so an integer mean raises no type question.

script.vtl
define viral propagation VP_1 (variable At_1) is
    aggregate avg
end viral propagation;

DS_r := DS_1 + DS_2;
Input DS_1
Id_1Me_1At_1
1101.5
2203.0
Input DS_2
Id_1Me_1At_1
114.0
222.0
Expected DS_r
Id_1Me_1At_1
1112.75
2222.5

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 ↗

Avg across two operators 🟢 pandas ✅ · DuckDB ✅
Tests:

aggregate avg at (DS_1 + DS_2) + DS_3: two operators, so At_1 follows their order of execution.

Manual:

define viral propagation: “avg is not associative, because an average does not record how many values it summarises”, and “Across the operators of an expression, the propagation follows their order of execution (precedence, associativity and parentheses), so the result depends on how the operations are grouped”, as the page shows on (DS_1 + DS_2) + DS_3. This is the clarification that #1175 asked for (sdmx-twg/vtl#744).

Expected:

At_1 avg(avg(1, 2), 6) = 3.75 and avg(avg(6, 2), 1) = 2.5, where the whole set would give 3; Me_1 111 and 222. The User Manual agrees: the propagation “is performed always in the same order of execution of the Operators of the expression”.

script.vtl
define viral propagation VP_1 (variable At_1) is
    aggregate avg
end viral propagation;

DS_r := (DS_1 + DS_2) + DS_3;
Input DS_1
Id_1Me_1At_1
1101.0
2206.0
Input DS_2
Id_1Me_1At_1
112.0
222.0
Input DS_3
Id_1Me_1At_1
11006.0
22001.0
Expected DS_r
Id_1Me_1At_1
11113.75
22222.5

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

Avg within one operator 🟢 pandas ✅ · DuckDB ✅
Tests:

aggregate avg at sum(DS_1 group by Id_1), one operator over three data points.

Manual:

define viral propagation: “Within one operator, avg is applied once to the whole set of operand values (e.g., the Data Points of a group or the Data Sets of a join), so the result does not depend on the order of the operands”, the clarification that #1175 asked for (sdmx-twg/vtl#744); the User Manual: “Within one operator, the result of A (in term of Attributes) is independent of the sequence of processing”, and in the Aggregate invocation “For invocation at Data Set level, the Attribute propagation rule is applied”.

Expected:

At_1 avg(1, 2, 6) = 3 in any order, where pair by pair it would give 3.75, 2.5 or 2.75; Me_1 60.

script.vtl
define viral propagation VP_1 (variable At_1) is
    aggregate avg
end viral propagation;

DS_r := sum(DS_1 group by Id_1);
Input DS_1
Id_1Id_2Me_1At_1
1A101.0
1B202.0
1C306.0
Expected DS_r
Id_1Me_1At_1
1603.0

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