define viral propagation
---
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
group byAnalytic invocation overCounting the number of data points countMinimum value minMaximum value maxMedian value medianSum sumAverage value avgPopulation standard deviation stddev_popSample standard deviation stddev_sampPopulation variance var_popSample variance var_sampFirst value first_valueLast value last_valueLag lagLead leadRank rankRatio to report ratio_to_reportData 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’sCONF_priority(“the CL_CONF list with C > N > F”), atDS_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_1C for the pair (C, N), N for (N, F) and F for (F, F) byelse, and it stays viral.
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;
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 10 | C |
| 2 | 20 | N |
| 3 | 30 | F |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 1 | N |
| 2 | 2 | F |
| 3 | 3 | F |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 11 | C |
| 2 | 22 | N |
| 3 | 33 | F |
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_1andVP_2, on the same variableAt_1, beforeDS_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”.
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;
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 10 | C |
| 2 | 20 | N |
| 3 | 30 | F |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 1 | N |
| 2 | 2 | F |
| 3 | 3 | F |
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’sCONF_priority, forAt_1, which the input structures define onCL_CONF(its type), atDS_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_1C for the pair (C, N), N for (N, F) and F for (F, F) byelse, and it stays viral and defined onCL_CONF.
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;
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 10 | C |
| 2 | 20 | N |
| 3 | 30 | F |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 1 | N |
| 2 | 2 | F |
| 3 | 3 | F |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 11 | C |
| 2 | 22 | N |
| 3 | 33 | F |
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"beforewhen "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_1N for (C, N), C for (C, F) and F for (F, F) byelse.
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;
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 10 | C |
| 2 | 20 | C |
| 3 | 30 | F |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 1 | N |
| 2 | 2 | F |
| 3 | 3 | F |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 11 | N |
| 2 | 22 | C |
| 3 | 33 | F |
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 unarywhen "M", as in the page’sCOMPUTED_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_1N for (C, M) and (M, C), M for (M, F) and F for (C, C) byelse. 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_defaultgives F for (E, E)), so (C, C) gives F as written.
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;
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 10 | C |
| 2 | 20 | M |
| 3 | 30 | M |
| 4 | 40 | C |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 1 | M |
| 2 | 2 | C |
| 3 | 3 | F |
| 4 | 4 | C |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 11 | N |
| 2 | 22 | N |
| 3 | 33 | M |
| 4 | 44 | F |
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_CandR_Nand an unnamedelse: the page’sCONF_prioritywith names.- Manual:
define viral propagation:
enumeratedClause ::= { ruleName : } when enumerationCondition then vpResultanddefaultClause ::= else vpResult.- Expected:
the names take no part in the matching:
At_1C for (C, N), N for (N, F) and F for (F, F), as without names.
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;
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 10 | C |
| 2 | 20 | N |
| 3 | 30 | F |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 1 | N |
| 2 | 2 | F |
| 3 | 3 | F |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 11 | C |
| 2 | 22 | N |
| 3 | 33 | F |
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_1C for (C, N), and F for (N, N) and (N, A) byelse. 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_defaultgives F for (E, E)), so (N, N) gives F as written.
define viral propagation VP_1 (variable At_1) is
when "C" then "C";
else "F"
end viral propagation;
DS_r := DS_1 + DS_2;
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 10 | C |
| 2 | 20 | N |
| 3 | 30 | N |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 1 | N |
| 2 | 2 | N |
| 3 | 3 | A |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 11 | C |
| 2 | 22 | F |
| 3 | 33 | F |
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 noelse.- Manual:
define viral propagation: “If omitted and no enumerated clause matches, NULL is propagated”.
- Expected:
At_1C 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_defaultgives F for (E, E)), so (N, N) gives null as written.
define viral propagation VP_1 (variable At_1) is
when "C" then "C"
end viral propagation;
DS_r := DS_1 + DS_2;
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 10 | C |
| 2 | 20 | N |
| 3 | 30 | N |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 1 | N |
| 2 | 2 | N |
| 3 | 3 | A |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 11 | C |
| 2 | 22 | |
| 3 | 33 |
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_19 and 18;At_1C for (C, F) bywhen "C"and F for (F, F) byelse.
define viral propagation VP_1 (variable At_1) is
when "C" then "C";
else "F"
end viral propagation;
DS_r := DS_1 - DS_2;
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 10 | C |
| 2 | 20 | F |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 1 | F |
| 2 | 2 | F |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 9 | C |
| 2 | 18 | F |
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), whereAt_1is 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_2and one viralAt_1: C for (C, F) and F for (F, F).
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);
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 10 | C |
| 2 | 20 | F |
| Id_1 | Me_2 | At_1 |
|---|---|---|
| 1 | 1 | F |
| 2 | 2 | F |
| Id_1 | Me_1 | Me_2 | At_1 |
|---|---|---|---|
| 1 | 10 | 1 | C |
| 2 | 20 | 2 | F |
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_115 withAt_1C for (C, F), and 7 with F for (F, F).
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);
| Id_1 | Id_2 | Me_1 | At_1 |
|---|---|---|---|
| 1 | A | 10 | C |
| 1 | B | 5 | F |
| 2 | A | 3 | F |
| 2 | B | 4 | F |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 15 | C |
| 2 | 7 | F |
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), withTOTAL = 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
computedkeeps “only the set of Data Points computed according to the Ruleset”.- Expected:
one
TOTALperId_1: 10 withAt_1C for (C, F), and 3 with F for (F, F).
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);
| Id_1 | Id_2 | Me_1 | At_1 |
|---|---|---|---|
| 1 | X | 4 | C |
| 1 | Y | 6 | F |
| 2 | X | 1 | F |
| 2 | Y | 2 | F |
| Id_1 | Id_2 | Me_1 | At_1 |
|---|---|---|---|
| 1 | TOTAL | 10 | C |
| 2 | TOTAL | 3 | F |
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 minon the Number viralAt_1, atDS_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_11.5 for (1.5, 4.0) and 2.0 for (3.0, 2.0);Me_111 and 22.
define viral propagation VP_1 (variable At_1) is
aggregate min
end viral propagation;
DS_r := DS_1 + DS_2;
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 10 | 1.5 |
| 2 | 20 | 3.0 |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 1 | 4.0 |
| 2 | 2 | 2.0 |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 11 | 1.5 |
| 2 | 22 | 2.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 maxon the Number viralAt_1, atDS_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_14.0 for (1.5, 4.0) and 3.0 for (3.0, 2.0);Me_111 and 22.
define viral propagation VP_1 (variable At_1) is
aggregate max
end viral propagation;
DS_r := DS_1 + DS_2;
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 10 | 1.5 |
| 2 | 20 | 3.0 |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 1 | 4.0 |
| 2 | 2 | 2.0 |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 11 | 4.0 |
| 2 | 22 | 3.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 sumon the Number viralAt_1, atDS_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_15.5 for (1.5, 4.0) and 5.0 for (3.0, 2.0);Me_111 and 22.
define viral propagation VP_1 (variable At_1) is
aggregate sum
end viral propagation;
DS_r := DS_1 + DS_2;
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 10 | 1.5 |
| 2 | 20 | 3.0 |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 1 | 4.0 |
| 2 | 2 | 2.0 |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 11 | 5.5 |
| 2 | 22 | 5.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 avgon the Number viralAt_1, atDS_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_12.75 for (1.5, 4.0) and 2.5 for (3.0, 2.0);Me_111 and 22. Over one pair both readings of #1175 give the mean, so no team decision applies, andAt_1is a Number, so an integer mean raises no type question.
define viral propagation VP_1 (variable At_1) is
aggregate avg
end viral propagation;
DS_r := DS_1 + DS_2;
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 10 | 1.5 |
| 2 | 20 | 3.0 |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 1 | 4.0 |
| 2 | 2 | 2.0 |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 11 | 2.75 |
| 2 | 22 | 2.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 avgat(DS_1 + DS_2) + DS_3: two operators, soAt_1follows 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_1avg(avg(1, 2), 6) = 3.75 and avg(avg(6, 2), 1) = 2.5, where the whole set would give 3;Me_1111 and 222. The User Manual agrees: the propagation “is performed always in the same order of execution of the Operators of the expression”.
define viral propagation VP_1 (variable At_1) is
aggregate avg
end viral propagation;
DS_r := (DS_1 + DS_2) + DS_3;
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 10 | 1.0 |
| 2 | 20 | 6.0 |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 1 | 2.0 |
| 2 | 2 | 2.0 |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 100 | 6.0 |
| 2 | 200 | 1.0 |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 111 | 3.75 |
| 2 | 222 | 2.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 avgatsum(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_1avg(1, 2, 6) = 3 in any order, where pair by pair it would give 3.75, 2.5 or 2.75;Me_160.
define viral propagation VP_1 (variable At_1) is
aggregate avg
end viral propagation;
DS_r := sum(DS_1 group by Id_1);
| Id_1 | Id_2 | Me_1 | At_1 |
|---|---|---|---|
| 1 | A | 10 | 1.0 |
| 1 | B | 20 | 2.0 |
| 1 | C | 30 | 6.0 |
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 60 | 3.0 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗