Union · union
---
config:
flowchart:
useMaxWidth: false
---
flowchart LR
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["Union · union<br/>🟢2"]:::ok
v_two["union(DS, DS)"]:::ok
v_n["union(DS, DS, ...)"]:::ok
v_two --- O
O --- v_n
click v_two href "#form-two"
click v_n href "#form-n"
Types
Takes any scalar · Gives any type
Comes from: any operator that returns a value
Goes to: whatever takes its input's type
Forms
union(DS, DS) 🟢 · any scalar → any type
Manual example 1 🟢 pandas ✅ · DuckDB ✅
- Tests:
union( DS_1, DS_2 ): two data sets that have no identifier combination in common.- Manual:
Union, Example 1, output verbatim: the resulting Data Set “contains the Data Points belonging to any of the operand Data Sets”.
- Expected:
the page’s five data points: the three of
DS_1and the two ofDS_2.
DS_r := union( DS_1, DS_2 );
| Id_1 | Id_2 | Id_3 | Id_4 | Me_1 |
|---|---|---|---|---|
| 2012 | B | Total | Total | 5 |
| 2012 | G | Total | Total | 2 |
| 2012 | F | Total | Total | 3 |
| Id_1 | Id_2 | Id_3 | Id_4 | Me_1 |
|---|---|---|---|---|
| 2012 | N | Total | Total | 23 |
| 2012 | S | Total | Total | 5 |
| Id_1 | Id_2 | Id_3 | Id_4 | Me_1 |
|---|---|---|---|---|
| 2012 | B | Total | Total | 5 |
| 2012 | G | Total | Total | 2 |
| 2012 | F | Total | Total | 3 |
| 2012 | N | Total | Total | 23 |
| 2012 | S | Total | Total | 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 ↗
Manual example 2 🟢 pandas ✅ · DuckDB ✅
- Tests:
union ( DS_1, DS_3 ): two data sets that share one data point, (2012, B, Total, Total), with the measure 5 inDS_1and 23 inDS_3.- Manual:
Union, Example 2, output verbatim: duplicate Data Points “are filtered by choosing the Data Point belonging to the left most operand Data Set”.
- Expected:
the page’s four data points: (2012, B, Total, Total) has the measure 5 of
DS_1, the leftmost operand, and not the 23 ofDS_3.
DS_r := union ( DS_1, DS_3 );
| Id_1 | Id_2 | Id_3 | Id_4 | Me_1 |
|---|---|---|---|---|
| 2012 | B | Total | Total | 5 |
| 2012 | G | Total | Total | 2 |
| 2012 | F | Total | Total | 3 |
| Id_1 | Id_2 | Id_3 | Id_4 | Me_1 |
|---|---|---|---|---|
| 2012 | B | Total | Total | 23 |
| 2012 | S | Total | Total | 5 |
| Id_1 | Id_2 | Id_3 | Id_4 | Me_1 |
|---|---|---|---|---|
| 2012 | B | Total | Total | 5 |
| 2012 | G | Total | Total | 2 |
| 2012 | F | Total | Total | 3 |
| 2012 | S | Total | Total | 5 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_3.csv · input/DS_3.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
Leftmost wins when measures differ 🟢 pandas ✅ · DuckDB ✅
- Tests:
union(DS_1, DS_2)where ids 2 and 3 are in both operands with different measures (Manual example 2 repeats one data point), to show which one the result keeps. The measure is 10 *Id_1+ k, with k 0 forDS_1and 1 forDS_2, so its last digit names the operand.- Manual:
Union: duplicate Data Points “are filtered by choosing the Data Point belonging to the left most operand Data Set”, whatever the other operand holds; the User Manual: “If for a common Data Point one or more dependent variables (Measures and Attributes) have different values in different Data Sets, the Data Point of the leftmost Data Set are returned in the result”.
- Expected:
Me_1is 10, 20, 30 and 41 for ids 1 to 4: ids 2 and 3 keep the values ofDS_1, the leftmost operand, and ids 1 and 4 are each in one operand only.
DS_r := union(DS_1, DS_2);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| 3 | 30 |
| Id_1 | Me_1 |
|---|---|
| 2 | 21 |
| 3 | 31 |
| 4 | 41 |
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| 3 | 30 |
| 4 | 41 |
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 ↗
union(DS, DS, ...) 🟢 · any scalar → any type
Leftmost of three operands wins 🟢 pandas ✅ · DuckDB ✅
- Tests:
union(DS_1, DS_2, DS_3), the list form with three operands, where the page’s examples have two: id 1 is only inDS_1, id 2 in all three, id 3 inDS_2andDS_3, and id 4 only inDS_3. The measure is 10 *Id_1+ k, with k 0, 1 and 2 forDS_1,DS_2andDS_3.- Manual:
Union:
dsList ::= ds { , ds }*, the resulting Data Set “contains the Data Points belonging to any of the operand Data Sets”, and duplicate Data Points “are filtered by choosing the Data Point belonging to the left most operand Data Set”.- Expected:
Me_1is 10, 20, 31 and 42 for ids 1 to 4: each id keeps the data point of its leftmost operand,DS_1,DS_1,DS_2andDS_3.
DS_r := union(DS_1, DS_2, DS_3);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_1 | Me_1 |
|---|---|
| 2 | 21 |
| 3 | 31 |
| Id_1 | Me_1 |
|---|---|
| 2 | 22 |
| 3 | 32 |
| 4 | 42 |
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| 3 | 31 |
| 4 | 42 |
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 ↗